Files
sodalive-ios/SodaLive/Sources/V2/CreatorChannel/Live/CreatorChannelLiveTabView.swift

77 lines
2.5 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) {
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)
}
}
}
struct CreatorChannelLiveTabView_Previews: PreviewProvider {
static var previews: some View {
CreatorChannelLiveTabView(
creatorId: 1,
isOwnCreatorChannel: true,
onTapLive: { _ in },
onTapContent: { _ in }
)
.background(Color.black)
.previewLayout(.sizeThatFits)
}
}