Files
sodalive-ios/SodaLive/Sources/V2/Main/Home/Following/MainHomeFollowingView.swift

119 lines
4.3 KiB
Swift

import SwiftUI
struct MainHomeFollowingView: View {
let onTapLive: (Int) -> Void
let onTapCreator: (Int) -> Void
let onTapContent: (Int) -> Void
let onTapLogin: () -> Void
let onTapFollowingAll: () -> Void
let onTapChatTab: () -> Void
let onTapChatRoom: (Int) -> Void
let onTapSchedule: (CreatorActivityType, Int) -> Void
let onTapCommunityPost: (Int) -> Void
@StateObject private var viewModel = MainHomeFollowingViewModel()
init(
onTapLive: @escaping (Int) -> Void = { _ in },
onTapCreator: @escaping (Int) -> Void = { _ in },
onTapContent: @escaping (Int) -> Void = { _ in },
onTapLogin: @escaping () -> Void = {},
onTapFollowingAll: @escaping () -> Void = {},
onTapChatTab: @escaping () -> Void = {},
onTapChatRoom: @escaping (Int) -> Void = { _ in },
onTapSchedule: @escaping (CreatorActivityType, Int) -> Void = { _, _ in },
onTapCommunityPost: @escaping (Int) -> Void = { _ in }
) {
self.onTapLive = onTapLive
self.onTapCreator = onTapCreator
self.onTapContent = onTapContent
self.onTapLogin = onTapLogin
self.onTapFollowingAll = onTapFollowingAll
self.onTapChatTab = onTapChatTab
self.onTapChatRoom = onTapChatRoom
self.onTapSchedule = onTapSchedule
self.onTapCommunityPost = onTapCommunityPost
}
var body: some View {
content
.onAppear {
if viewModel.hasLoaded == false {
viewModel.fetchFollowing()
}
}
}
@ViewBuilder
private var content: some View {
if viewModel.isLoading {
ProgressView()
.tint(.white)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.black)
} else if viewModel.isLoginRequired {
MainHomeFollowingEmptyStateView(
message: I18n.HomeFollowing.loginRequiredMessage,
loginAction: onTapLogin
)
} else if !viewModel.message.isEmpty {
MainHomeFollowingEmptyStateView(message: viewModel.message)
} else if let response = viewModel.response {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
MainHomeFollowingCreatorSection(
followingCreators: response.followingCreators,
onTapCreator: onTapCreator,
onTapAll: onTapFollowingAll
)
if !response.onAirLives.isEmpty {
MainHomeFollowingLiveSection(
onAirLives: response.onAirLives,
onTapLive: onTapLive
)
.padding(.top, 28)
}
if !response.recentChats.isEmpty {
MainHomeFollowingChatSection(
recentChats: response.recentChats,
onTapTitle: onTapChatTab,
onTapChatRoom: onTapChatRoom
)
.padding(.top, 48)
}
if !response.monthlySchedules.isEmpty {
MainHomeFollowingScheduleSection(
monthlySchedules: response.monthlySchedules,
onTapSchedule: onTapSchedule
)
.padding(.top, 48)
}
if !response.recentNews.isEmpty {
MainHomeFollowingNewsSection(
recentNews: response.recentNews,
onTapCreator: onTapCreator,
onTapContent: onTapContent,
onTapCommunityPost: onTapCommunityPost
)
.padding(.top, 48)
}
}
.padding(.bottom, SodaSpacing.s20)
}
.background(Color.black)
} else {
MainHomeFollowingEmptyStateView(message: I18n.HomeFollowing.emptyStateMessage)
}
}
}
struct MainHomeFollowingView_Previews: PreviewProvider {
static var previews: some View {
MainHomeFollowingView()
}
}