89 lines
3.2 KiB
Swift
89 lines
3.2 KiB
Swift
//
|
|
// SeriesMainByGenreView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 11/14/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SeriesMainByGenreView: View {
|
|
|
|
@StateObject var viewModel = SeriesMainByGenreViewModel()
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
VStack(spacing: 16) {
|
|
if !viewModel.genreList.isEmpty {
|
|
SeriesMainGenreView(
|
|
genreList: viewModel.genreList,
|
|
selectGenre: viewModel.onTapGenre,
|
|
selectedGenre: $viewModel.selectedGenre
|
|
)
|
|
}
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
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.seriesList.indices, id: \.self) { index in
|
|
let item = viewModel.seriesList[index]
|
|
NavigationLink {
|
|
SeriesDetailView(seriesId: item.seriesId)
|
|
} label: {
|
|
SeriesMainItemView(item: item, width: width, height: width * 227 / 160)
|
|
.contentShape(Rectangle())
|
|
.onAppear {
|
|
if index == viewModel.seriesList.count - 1 {
|
|
viewModel.getSeriesListByGenre()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.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)
|
|
.appFont(size: 12, weight: .medium)
|
|
.background(Color.button)
|
|
.foregroundColor(Color.white)
|
|
.multilineTextAlignment(.leading)
|
|
.cornerRadius(20)
|
|
.padding(.bottom, 66.7)
|
|
Spacer()
|
|
}
|
|
}
|
|
.onAppear {
|
|
viewModel.getGenreList()
|
|
}
|
|
|
|
if viewModel.isLoading {
|
|
LoadingView()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
SeriesMainByGenreView()
|
|
}
|