56 lines
1.7 KiB
Swift
56 lines
1.7 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
|
|
|
|
@StateObject private var viewModel = MainHomeRecommendationViewModel()
|
|
|
|
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
|
|
)
|
|
}
|
|
.padding(.vertical, SodaSpacing.s20)
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
if viewModel.recommendations == nil {
|
|
viewModel.fetchRecommendations()
|
|
}
|
|
}
|
|
.sodaToast(
|
|
isPresented: $viewModel.isShowPopup,
|
|
message: viewModel.errorMessage,
|
|
autohideIn: 2
|
|
)
|
|
}
|
|
}
|
|
|
|
struct MainHomeRecommendationView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MainHomeRecommendationView(
|
|
onTapLive: { _ in },
|
|
onTapCreator: { _ in },
|
|
onTapContent: { _ in },
|
|
onTapCharacter: { _ in },
|
|
onTapCommunity: { _ in }
|
|
)
|
|
}
|
|
}
|