133 lines
5.7 KiB
Swift
133 lines
5.7 KiB
Swift
//
|
|
// SeriesMainHomeView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 11/14/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SeriesMainHomeView: View {
|
|
|
|
@StateObject var viewModel = SeriesMainHomeViewModel()
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
VStack(spacing: 48) {
|
|
if !viewModel.banners.isEmpty {
|
|
SeriesMainHomeBannerView(bannerList: viewModel.banners)
|
|
.padding(.top, 24)
|
|
}
|
|
|
|
if !viewModel.completedSeriesList.isEmpty {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
HStack(spacing: 0) {
|
|
Text("완결 시리즈")
|
|
.font(.custom(Font.preBold.rawValue, size: 24))
|
|
.foregroundColor(.white)
|
|
|
|
Spacer()
|
|
|
|
Text("전체보기")
|
|
.font(.custom(Font.preRegular.rawValue, size: 14))
|
|
.foregroundColor(.init(hex: "78909C"))
|
|
.onTapGesture {
|
|
AppState.shared
|
|
.setAppStep(step: .seriesAll(isCompleted: true))
|
|
}
|
|
}
|
|
.padding(.horizontal, 24)
|
|
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
LazyHStack(spacing: 16) {
|
|
ForEach(0..<viewModel.completedSeriesList.count, id: \.self) {
|
|
let item = viewModel.completedSeriesList[$0]
|
|
NavigationLink {
|
|
SeriesDetailView(seriesId: item.seriesId)
|
|
} label: {
|
|
SeriesMainItemView(item: item)
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, 24)
|
|
}
|
|
}
|
|
}
|
|
|
|
if !viewModel.recommendSeriesList.isEmpty {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
HStack(spacing: 0) {
|
|
Text("추천 시리즈")
|
|
.font(.custom(Font.preBold.rawValue, size: 24))
|
|
.foregroundColor(.white)
|
|
|
|
Spacer()
|
|
|
|
Image("ic_refresh")
|
|
.onTapGesture {
|
|
viewModel.getRecommendSeriesList()
|
|
}
|
|
}
|
|
.padding(.horizontal, 24)
|
|
|
|
let horizontalPadding: CGFloat = 24
|
|
let gridSpacing: CGFloat = 16
|
|
let width = (screenSize().width - (horizontalPadding * 2) - gridSpacing) / 2
|
|
|
|
LazyVGrid(
|
|
columns: Array(
|
|
repeating: GridItem(
|
|
.flexible(),
|
|
spacing: gridSpacing,
|
|
alignment: .topLeading
|
|
),
|
|
count: 2
|
|
),
|
|
alignment: .leading,
|
|
spacing: gridSpacing
|
|
) {
|
|
ForEach(viewModel.recommendSeriesList.indices, id: \.self) {
|
|
let item = viewModel.recommendSeriesList[$0]
|
|
NavigationLink {
|
|
SeriesDetailView(seriesId: item.seriesId)
|
|
} label: {
|
|
SeriesMainItemView(item: item, width: width, height: width * 227 / 160)
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, horizontalPadding)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .bottom, 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()
|
|
}
|
|
}
|
|
.onAppear {
|
|
viewModel.fetchHome()
|
|
}
|
|
|
|
if viewModel.isLoading {
|
|
LoadingView()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
SeriesMainHomeView()
|
|
}
|