77 lines
2.6 KiB
Swift
77 lines
2.6 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelDonationTabView: View {
|
|
let creatorId: Int
|
|
let isOwnCreatorChannel: Bool
|
|
@ObservedObject var viewModel: CreatorChannelDonationViewModel
|
|
let onTapViewAll: () -> Void
|
|
let onTapDonate: () -> Void
|
|
|
|
var body: some View {
|
|
content
|
|
.background(Color.black)
|
|
.onAppear {
|
|
if viewModel.hasLoaded == false {
|
|
viewModel.fetchFirstPage(creatorId: creatorId)
|
|
}
|
|
}
|
|
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 1)
|
|
}
|
|
|
|
private var content: some View {
|
|
VStack(spacing: 0) {
|
|
CreatorChannelDonationCountBar(donationCount: viewModel.donationCount)
|
|
|
|
if isEmptyState {
|
|
CreatorChannelDonationEmptyView(
|
|
showsDonateButton: isOwnCreatorChannel == false,
|
|
onTapDonate: onTapDonate
|
|
)
|
|
} else {
|
|
CreatorChannelDonationRankingSection(
|
|
rankings: viewModel.rankings,
|
|
onTapViewAll: onTapViewAll
|
|
)
|
|
|
|
LazyVStack(spacing: SodaSpacing.s8) {
|
|
ForEach(viewModel.donations.indices, id: \.self) { index in
|
|
CreatorChannelDonationCard(donation: viewModel.donations[index])
|
|
.padding(.horizontal, SodaSpacing.s14)
|
|
.onAppear {
|
|
viewModel.fetchNextPageIfNeeded(
|
|
creatorId: creatorId,
|
|
currentItem: viewModel.donations[index]
|
|
)
|
|
}
|
|
}
|
|
|
|
if viewModel.isLoadingNextPage {
|
|
ProgressView()
|
|
.padding(.vertical, SodaSpacing.s20)
|
|
}
|
|
}
|
|
.padding(.bottom, SodaSpacing.s20)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var isEmptyState: Bool {
|
|
guard viewModel.hasLoaded else { return false }
|
|
return viewModel.rankings.isEmpty && viewModel.donationCount == 0
|
|
}
|
|
}
|
|
|
|
struct CreatorChannelDonationTabView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CreatorChannelDonationTabView(
|
|
creatorId: 1,
|
|
isOwnCreatorChannel: false,
|
|
viewModel: CreatorChannelDonationViewModel(),
|
|
onTapViewAll: {},
|
|
onTapDonate: {}
|
|
)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|