88 lines
2.9 KiB
Swift
88 lines
2.9 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelLiveTabView: View {
|
|
let creatorId: Int
|
|
let isOwnCreatorChannel: Bool
|
|
let onTapLive: (Int) -> Void
|
|
let onTapContent: (Int) -> Void
|
|
let onTapCreateLive: () -> Void
|
|
|
|
@StateObject private var viewModel = CreatorChannelLiveViewModel()
|
|
@State private var isSortSheetPresented = false
|
|
|
|
var body: some View {
|
|
ZStack(alignment: .bottom) {
|
|
content
|
|
|
|
if isOwnCreatorChannel {
|
|
CreatorChannelLiveStartButton(action: onTapCreateLive)
|
|
.padding(.horizontal, SodaSpacing.s20)
|
|
.padding(.bottom, SodaSpacing.s20)
|
|
}
|
|
}
|
|
.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) {
|
|
CreatorChannelSortBar(
|
|
totalCount: viewModel.response?.liveReplayContentCount ?? 0,
|
|
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 ? 96 : SodaSpacing.s20)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CreatorChannelLiveTabView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CreatorChannelLiveTabView(
|
|
creatorId: 1,
|
|
isOwnCreatorChannel: true,
|
|
onTapLive: { _ in },
|
|
onTapContent: { _ in },
|
|
onTapCreateLive: {}
|
|
)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|