95 lines
3.2 KiB
Swift
95 lines
3.2 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelLiveTabView: View {
|
|
let creatorId: Int
|
|
let isOwnCreatorChannel: Bool
|
|
let onTapLive: (Int) -> Void
|
|
let onTapContent: (Int) -> Void
|
|
|
|
@StateObject private var viewModel = CreatorChannelLiveViewModel()
|
|
@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 {
|
|
CreatorChannelSortBar(
|
|
selectedSort: viewModel.selectedSort,
|
|
onTapSort: {
|
|
isSortSheetPresented = true
|
|
}
|
|
)
|
|
|
|
LazyVStack(spacing: 0) {
|
|
CreatorChannelCurrentLiveSection(
|
|
currentLive: viewModel.response?.currentLive,
|
|
onTapLive: onTapLive
|
|
)
|
|
.padding(.top, SodaSpacing.s14)
|
|
.padding(.bottom, SodaSpacing.s12)
|
|
|
|
ForEach(viewModel.liveReplayContents) { 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 isEmptyState: Bool {
|
|
guard viewModel.hasLoaded, let response = viewModel.response else { return false }
|
|
return response.currentLive == nil && response.liveReplayContentCount == 0
|
|
}
|
|
|
|
private var emptyStateView: some View {
|
|
Text(I18n.CreatorChannelLive.emptyMessage)
|
|
.appFont(.body3)
|
|
.foregroundColor(Color.gray500)
|
|
.multilineTextAlignment(.center)
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 48)
|
|
}
|
|
}
|
|
|
|
struct CreatorChannelLiveTabView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CreatorChannelLiveTabView(
|
|
creatorId: 1,
|
|
isOwnCreatorChannel: true,
|
|
onTapLive: { _ in },
|
|
onTapContent: { _ in }
|
|
)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|