109 lines
3.9 KiB
Swift
109 lines
3.9 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelAudioTabView: View {
|
|
let creatorId: Int
|
|
let isOwnCreatorChannel: Bool
|
|
let onTapContent: (Int) -> Void
|
|
|
|
@StateObject private var viewModel = CreatorChannelAudioViewModel()
|
|
@State private var isSortSheetPresented = false
|
|
|
|
var body: some View {
|
|
content
|
|
.background(Color.black)
|
|
.onAppear {
|
|
if viewModel.hasLoaded == false {
|
|
viewModel.fetchFirstPage(creatorId: creatorId)
|
|
}
|
|
}
|
|
.sheet(isPresented: $isSortSheetPresented) {
|
|
CreatorChannelSortBottomSheet(selectedSort: viewModel.selectedSort) { sort in
|
|
viewModel.selectSort(sort, creatorId: creatorId)
|
|
isSortSheetPresented = false
|
|
}
|
|
}
|
|
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 1)
|
|
}
|
|
|
|
private var content: some View {
|
|
VStack(spacing: 0) {
|
|
if isEmptyState {
|
|
emptyStateView
|
|
} else {
|
|
CapsuleTabBar(
|
|
items: viewModel.displayThemes,
|
|
selectedItem: Binding(
|
|
get: { viewModel.selectedTheme },
|
|
set: { viewModel.selectTheme($0, creatorId: creatorId) }
|
|
),
|
|
title: { $0.themeName }
|
|
)
|
|
|
|
CreatorChannelSortBar(
|
|
selectedSort: viewModel.selectedSort,
|
|
onTapSort: {
|
|
isSortSheetPresented = true
|
|
}
|
|
)
|
|
|
|
LazyVStack(spacing: 0) {
|
|
if shouldShowOwnershipRate, let response = viewModel.response {
|
|
CreatorChannelAudioOwnershipRateView(
|
|
purchasedAudioContentRate: response.purchasedAudioContentRate,
|
|
purchasedAudioContentCount: response.purchasedAudioContentCount,
|
|
paidAudioContentCount: response.paidAudioContentCount
|
|
)
|
|
.padding(.bottom, SodaSpacing.s8)
|
|
}
|
|
|
|
ForEach(viewModel.audioContents) { audioContent in
|
|
CreatorChannelAudioContentListItem(audioContent: audioContent) {
|
|
onTapContent(audioContent.audioContentId)
|
|
}
|
|
.onAppear {
|
|
viewModel.fetchNextPageIfNeeded(creatorId: creatorId, currentItem: audioContent)
|
|
}
|
|
}
|
|
|
|
if viewModel.isLoadingNextPage {
|
|
ProgressView()
|
|
.padding(.vertical, SodaSpacing.s20)
|
|
}
|
|
}
|
|
.padding(.bottom, isOwnCreatorChannel ? 70 : SodaSpacing.s20)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var shouldShowOwnershipRate: Bool {
|
|
guard isOwnCreatorChannel == false else { return false }
|
|
return viewModel.isAllThemeSelected
|
|
}
|
|
|
|
private var isEmptyState: Bool {
|
|
guard viewModel.hasLoaded, let response = viewModel.response else { return false }
|
|
return response.audioContentCount == 0
|
|
}
|
|
|
|
private var emptyStateView: some View {
|
|
Text(I18n.CreatorChannelAudio.emptyMessage)
|
|
.appFont(.body3)
|
|
.foregroundColor(Color.gray500)
|
|
.multilineTextAlignment(.center)
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 48)
|
|
}
|
|
}
|
|
|
|
struct CreatorChannelAudioTabView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CreatorChannelAudioTabView(
|
|
creatorId: 1,
|
|
isOwnCreatorChannel: false,
|
|
onTapContent: { _ in }
|
|
)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|