Files
sodalive-ios/SodaLive/Sources/Home/HomeTabView.swift
Yu Sung 07c73366e9 feat: 메인 홈
- 주간 차트, 무료 콘텐츠 UI 추가
2025-07-12 02:50:24 +09:00

232 lines
11 KiB
Swift

//
// HomeTabView.swift
// SodaLive
//
// Created by klaus on 7/10/25.
//
import SwiftUI
struct HomeTabView: View {
@StateObject var viewModel = HomeTabViewModel()
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
@AppStorage("role") private var role: String = UserDefaults.string(forKey: UserDefaultsKey.role)
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
ZStack(alignment: .bottomTrailing) {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 0) {
Image("img_text_logo")
Spacer()
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
Image("ic_can")
.onTapGesture {
AppState
.shared
.setAppStep(step: .canCharge(refresh: {}))
}
}
}
.padding(.horizontal, 24)
.padding(.vertical, 20)
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 48) {
if !viewModel.liveList.isEmpty {
VStack(alignment: .leading, spacing: 16) {
HStack(spacing: 0) {
Text("지금")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.button)
Text(" 라이브중")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.white)
}
.padding(.horizontal, 24)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
ForEach(0..<viewModel.liveList.count, id: \.self) {
HomeLiveItemView(item: viewModel.liveList[$0])
}
}
.padding(.horizontal, 24)
}
}
}
if !viewModel.creatorRanking.isEmpty {
VStack(alignment: .leading, spacing: 16) {
HStack(spacing: 0) {
Text("인기")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.button)
Text(" 크리에이터")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.white)
}
.padding(.horizontal, 24)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
ForEach(0..<viewModel.creatorRanking.count, id: \.self) {
HomeCreatorRankingItemView(rank: $0 + 1, item: viewModel.creatorRanking[$0])
}
}
.padding(.horizontal, 24)
}
}
}
VStack(alignment: .leading, spacing: 16) {
HomeLatestContentView(
onClickMore: {
AppState.shared
.setAppStep(step: .newContentAll(isFree: false))
},
themeList: viewModel.latestContentThemeList,
contentList: viewModel.latestContentList
) {
viewModel.getLatestContentByTheme(theme: $0)
}
}
if !viewModel.eventBannerList.isEmpty {
SectionEventBannerView(items: viewModel.eventBannerList)
}
if !viewModel.originalAudioDramaList.isEmpty {
VStack(alignment: .leading, spacing: 16) {
HStack(spacing: 0) {
Text("오직")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.button)
Text(" 보이스온에서만")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.white)
}
.padding(.horizontal, 24)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
ForEach(0..<viewModel.originalAudioDramaList.count, id: \.self) {
SeriesItemView(item: viewModel.originalAudioDramaList[$0])
}
}
.padding(.horizontal, 24)
}
}
}
if !viewModel.auditionList.isEmpty {
HomeAuditionView(items: viewModel.auditionList)
}
DayOfWeekSeriesView(seriesList: viewModel.dayOfWeekSeriesList) {
viewModel.getDayOfWeekSeriesList(dayOfWeek: $0)
}
if !viewModel.contentRanking.isEmpty {
HomeWeeklyChartView(contentList: viewModel.contentRanking)
}
VStack(alignment: .leading, spacing: 16) {
HStack(spacing: 0) {
Text("추천")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.button)
Text(" 채널")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.white)
}
.padding(.horizontal, 24)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
}
.padding(.horizontal, 24)
}
}
if !viewModel.freeContentList.isEmpty {
VStack(alignment: .leading, spacing: 16) {
HStack(spacing: 0) {
Text("무료")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.button)
Text(" 콘텐츠")
.font(.custom(Font.preBold.rawValue, size: 26))
.foregroundColor(.white)
}
.padding(.horizontal, 24)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
ForEach(0..<viewModel.freeContentList.count, id: \.self) { index in
ContentItemView(item: viewModel.freeContentList[index])
}
}
.padding(.horizontal, 24)
}
}
}
Text("""
- 회사명 : 주식회사 소다라이브
- 대표자 : 이재형
- 주소 : 경기도 성남시 분당구 황새울로335번길 10, 5층 563A호
- 사업자등록번호 : 870-81-03220
- 통신판매업신고 : 제2024-성남분당B-1012호
- 고객센터 : 02.2055.1477 (이용시간 10:00~19:00)
- 대표 이메일 : sodalive.official@gmail.com
""")
.font(.custom(Font.medium.rawValue, size: 11))
.foregroundColor(Color.gray77)
.padding(.top, 30)
.padding(.horizontal, 13.3)
}
.padding(.vertical, 24)
}
}
}
.onAppear {
viewModel.fetchData()
}
}
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
HStack {
Spacer()
Text(viewModel.errorMessage)
.padding(.vertical, 13.3)
.frame(width: screenSize().width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color.button)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.cornerRadius(20)
.padding(.bottom, 66.7)
Spacer()
}
}
}
}
#Preview {
HomeTabView()
}