156 lines
4.9 KiB
Swift
156 lines
4.9 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelView: View {
|
|
let creatorId: Int
|
|
|
|
@StateObject private var viewModel = CreatorChannelViewModel()
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
init(creatorId: Int, viewModel: CreatorChannelViewModel = CreatorChannelViewModel()) {
|
|
self.creatorId = creatorId
|
|
_viewModel = StateObject(wrappedValue: viewModel)
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Color.black.ignoresSafeArea()
|
|
|
|
ZStack(alignment: .top) {
|
|
VStack(spacing: 0) {
|
|
headerSection
|
|
tabBar
|
|
selectedTabContent
|
|
}
|
|
|
|
titleBar
|
|
}
|
|
|
|
if viewModel.isLoading {
|
|
LoadingView()
|
|
}
|
|
}
|
|
.navigationBarBackButtonHidden(true)
|
|
.onAppear {
|
|
if viewModel.hasLoaded == false {
|
|
viewModel.fetchHome(creatorId: creatorId)
|
|
}
|
|
}
|
|
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 1)
|
|
}
|
|
|
|
private var titleBar: some View {
|
|
CreatorChannelTitleBar(
|
|
isFollow: viewModel.response?.creator.isFollow ?? false,
|
|
isNotify: viewModel.response?.creator.isNotify ?? false,
|
|
backgroundProgress: 0,
|
|
onTapBack: {
|
|
dismiss()
|
|
},
|
|
onTapFollow: {
|
|
viewModel.creatorFollow(follow: true, notify: true)
|
|
},
|
|
onTapUnfollow: {
|
|
viewModel.creatorFollow(follow: false, notify: false)
|
|
},
|
|
onTapNotify: {
|
|
viewModel.creatorFollow(follow: true, notify: true)
|
|
},
|
|
onTapUnnotify: {
|
|
viewModel.creatorFollow(follow: true, notify: false)
|
|
},
|
|
onTapMore: {}
|
|
)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var headerSection: some View {
|
|
if let creator = viewModel.response?.creator {
|
|
CreatorChannelHeaderSection(creator: creator)
|
|
}
|
|
}
|
|
|
|
private var tabBar: some View {
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
HStack(spacing: 20) {
|
|
ForEach(CreatorChannelTab.allCases, id: \.self) { tab in
|
|
Button {
|
|
viewModel.selectedTab = tab
|
|
} label: {
|
|
VStack(spacing: 8) {
|
|
Text(tab.title)
|
|
.font(.system(size: 15, weight: viewModel.selectedTab == tab ? .semibold : .regular))
|
|
.foregroundColor(viewModel.selectedTab == tab ? .white : Color.gray500)
|
|
|
|
Rectangle()
|
|
.fill(viewModel.selectedTab == tab ? Color.soda400 : Color.clear)
|
|
.frame(height: 2)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, 20)
|
|
}
|
|
.frame(height: 48)
|
|
.background(Color.black)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var selectedTabContent: some View {
|
|
if viewModel.selectedTab != .home || viewModel.isApiFailedPlaceholderVisible {
|
|
CreatorChannelPlaceholderTabView(title: viewModel.selectedTab.title)
|
|
} else if let response = viewModel.response {
|
|
CreatorChannelHomeView(response: response) { tab in
|
|
viewModel.selectedTab = tab
|
|
}
|
|
} else {
|
|
CreatorChannelPlaceholderTabView(title: CreatorChannelTab.home.title)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let viewModel = CreatorChannelViewModel()
|
|
viewModel.response = CreatorChannelHomeResponse(
|
|
creator: CreatorChannelCreatorResponse(
|
|
creatorId: 1,
|
|
characterId: 10,
|
|
nickname: "Soda Creator",
|
|
profileImageUrl: "https://picsum.photos/600",
|
|
followerCount: 12345,
|
|
isAiChatAvailable: true,
|
|
isDmAvailable: false,
|
|
isFollow: true,
|
|
isNotify: true
|
|
),
|
|
currentLive: nil,
|
|
latestAudioContent: nil,
|
|
channelDonations: [],
|
|
notices: [],
|
|
schedules: [],
|
|
audioContents: [],
|
|
series: [],
|
|
communities: [],
|
|
fanTalk: CreatorChannelFanTalkSummaryResponse(totalCount: 0, latestFanTalk: nil),
|
|
introduce: "",
|
|
activity: CreatorChannelActivityResponse(
|
|
debutDateUtc: nil,
|
|
dday: "D+1",
|
|
liveCount: 0,
|
|
liveDurationHours: 0,
|
|
liveContributorCount: 0,
|
|
audioContentCount: 0,
|
|
seriesCount: 0
|
|
),
|
|
sns: CreatorChannelSnsResponse(
|
|
instagramUrl: "",
|
|
fancimmUrl: "",
|
|
xurl: "",
|
|
youtubeUrl: "",
|
|
kakaoOpenChatUrl: ""
|
|
)
|
|
)
|
|
viewModel.hasLoaded = true
|
|
|
|
return CreatorChannelView(creatorId: 1, viewModel: viewModel)
|
|
}
|