139 lines
5.6 KiB
Swift
139 lines
5.6 KiB
Swift
import SwiftUI
|
|
|
|
struct MainHomeRecommendationView: View {
|
|
let onTapLive: (Int) -> Void
|
|
let onTapCreator: (Int) -> Void
|
|
let onTapContent: (Int) -> Void
|
|
let onTapCharacter: (Int) -> Void
|
|
let onTapCommunity: (Int) -> Void
|
|
let onTapBanner: (RecommendationBannerResponse) -> Void
|
|
let onTapFollowAll: (@escaping () -> Void) -> Void
|
|
|
|
@StateObject private var viewModel = MainHomeRecommendationViewModel()
|
|
@StateObject private var communityMediaPlayer = CreatorCommunityMediaPlayerManager.shared
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Color.black
|
|
.ignoresSafeArea()
|
|
|
|
if viewModel.isLoading && viewModel.recommendations == nil {
|
|
ProgressView()
|
|
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
|
} else {
|
|
ScrollView(showsIndicators: false) {
|
|
VStack(alignment: .leading, spacing: SodaSpacing.s24) {
|
|
MainHomeLiveSection(
|
|
items: viewModel.recommendations?.lives ?? [],
|
|
onTapLive: onTapLive
|
|
)
|
|
|
|
MainHomeBannerSection(
|
|
items: viewModel.recommendations?.banners ?? [],
|
|
onTapBanner: onTapBanner
|
|
)
|
|
|
|
MainHomeActiveCreatorSection(
|
|
items: viewModel.recommendations?.recentlyActiveCreators ?? [],
|
|
onTapLive: onTapLive,
|
|
onTapContent: onTapContent,
|
|
onTapCommunity: onTapCommunity
|
|
)
|
|
|
|
MainHomeRecentDebutCreatorSection(
|
|
items: viewModel.recommendations?.recentDebutCreators ?? [],
|
|
onTapCreator: onTapCreator
|
|
)
|
|
|
|
MainHomeAiCharacterSection(
|
|
items: viewModel.recommendations?.aiCharacters ?? [],
|
|
onTapCharacter: onTapCharacter
|
|
)
|
|
|
|
MainHomeGenreCreatorSection(
|
|
items: viewModel.recommendations?.genreCreators ?? [],
|
|
isFollowAllCompleted: viewModel.isFollowAllCompleted,
|
|
isFollowAllLoading: viewModel.isFollowAllLoading,
|
|
onTapCreator: onTapCreator,
|
|
onTapFollowAll: { creatorIds, completionKey in
|
|
onTapFollowAll {
|
|
viewModel.followAll(creatorIds: creatorIds, completionKey: completionKey)
|
|
}
|
|
}
|
|
)
|
|
|
|
MainHomeCheerCreatorSection(
|
|
items: viewModel.recommendations?.cheerCreators ?? [],
|
|
isFollowAllCompleted: viewModel.isFollowAllCompleted("cheer"),
|
|
isFollowAllLoading: viewModel.isFollowAllLoading("cheer"),
|
|
onTapCreator: onTapCreator,
|
|
onTapFollowAll: {
|
|
onTapFollowAll {
|
|
viewModel.followAll(
|
|
creatorIds: viewModel.recommendations?.cheerCreators.map(\.creatorId) ?? [],
|
|
completionKey: "cheer"
|
|
)
|
|
}
|
|
}
|
|
)
|
|
|
|
MainHomePopularCommunitySection(
|
|
items: viewModel.recommendations?.popularCommunityPosts ?? [],
|
|
onTapCommunity: onTapCommunity,
|
|
onTapLike: { postId in
|
|
viewModel.likeCommunityPost(postId: postId)
|
|
},
|
|
onTapPurchase: { item in
|
|
viewModel.openCommunityPostPurchase(postId: item.postId, price: item.price)
|
|
}
|
|
)
|
|
}
|
|
.padding(.vertical, SodaSpacing.s20)
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
if viewModel.recommendations == nil {
|
|
viewModel.fetchRecommendations()
|
|
}
|
|
}
|
|
.sodaToast(
|
|
isPresented: $viewModel.isShowPopup,
|
|
message: viewModel.errorMessage,
|
|
autohideIn: 2
|
|
)
|
|
.sodaToast(
|
|
isPresented: $communityMediaPlayer.isShowPopup,
|
|
message: communityMediaPlayer.errorMessage,
|
|
autohideIn: 2
|
|
)
|
|
.overlay {
|
|
if viewModel.isShowCommunityPostPurchaseDialog {
|
|
CommunityPostPurchaseDialog(
|
|
isShowing: $viewModel.isShowCommunityPostPurchaseDialog,
|
|
can: viewModel.purchasingCommunityPostPrice,
|
|
confirmAction: viewModel.purchaseCommunityPost
|
|
)
|
|
}
|
|
|
|
if communityMediaPlayer.isLoading {
|
|
LoadingView()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MainHomeRecommendationView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MainHomeRecommendationView(
|
|
onTapLive: { _ in },
|
|
onTapCreator: { _ in },
|
|
onTapContent: { _ in },
|
|
onTapCharacter: { _ in },
|
|
onTapCommunity: { _ in },
|
|
onTapBanner: { _ in },
|
|
onTapFollowAll: { action in action() }
|
|
)
|
|
}
|
|
}
|