Files
sodalive-ios/SodaLive/Sources/Chat/Character/CharacterView.swift

93 lines
3.6 KiB
Swift

//
// CharacterView.swift
// SodaLive
//
// Created by klaus on 8/29/25.
//
import SwiftUI
struct CharacterView: View {
@StateObject var viewModel = CharacterViewModel()
private let horizontalPadding: CGFloat = 16
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 24) {
//
if !viewModel.banners.isEmpty {
AutoSlideCharacterBannerView(items: viewModel.banners) { banner in
AppState.shared.setAppStep(step: .characterDetail(characterId: banner.characterId))
}
}
//
if !viewModel.recentCharacters.isEmpty {
RecentCharacterSectionView(
titleCount: viewModel.recentCharacters.count,
items: viewModel.recentCharacters
) { ch in
AppState.shared.setAppStep(step: .characterDetail(characterId: ch.characterId))
}
}
//
if !viewModel.newCharacters.isEmpty {
CharacterSectionView(
title: "신규 캐릭터",
items: viewModel.newCharacters
) { ch in
AppState.shared.setAppStep(step: .characterDetail(characterId: ch.characterId))
}
}
// ( )
if !viewModel.curations.isEmpty {
VStack(alignment: .leading, spacing: 24) {
ForEach(viewModel.curations.indices, id: \.self) { idx in
let section = viewModel.curations[idx]
CharacterSectionView(
title: section.title,
items: section.characters
) { ch in
AppState.shared.setAppStep(step: .characterDetail(characterId: ch.characterId))
}
}
}
}
}
.padding(.vertical, 24)
}
.background(Color.black.ignoresSafeArea())
.onAppear {
if !viewModel.isLoading {
viewModel.getCharacterMain()
}
}
}
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
GeometryReader { geo in
HStack {
Spacer()
Text(viewModel.errorMessage)
.padding(.vertical, 13.3)
.frame(width: geo.size.width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color.button)
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.cornerRadius(20)
.padding(.top, 66.7)
Spacer()
}
}
}
}
}
#Preview {
CharacterView()
}