feat(chat): 캐릭터 상세 이동 로직 ChatTabView로 이관 및 로그인/본인인증 처리 추가
This commit is contained in:
@@ -50,6 +50,9 @@ class AppState: ObservableObject {
|
||||
@Published var marketingUtmMedium = ""
|
||||
@Published var marketingUtmCampaign = ""
|
||||
|
||||
@Published var isShowErrorPopup = false
|
||||
@Published var errorMessage = ""
|
||||
|
||||
func setAppStep(step: AppStep) {
|
||||
switch step {
|
||||
case .splash, .main:
|
||||
|
||||
@@ -12,6 +12,8 @@ struct CharacterView: View {
|
||||
|
||||
private let horizontalPadding: CGFloat = 16
|
||||
|
||||
let onSelectCharacter: (Int) -> Void
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
@@ -19,7 +21,7 @@ struct CharacterView: View {
|
||||
// 배너
|
||||
if !viewModel.banners.isEmpty {
|
||||
AutoSlideCharacterBannerView(items: viewModel.banners) { banner in
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: banner.characterId))
|
||||
onSelectCharacter(banner.characterId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +31,7 @@ struct CharacterView: View {
|
||||
titleCount: viewModel.recentCharacters.count,
|
||||
items: viewModel.recentCharacters
|
||||
) { ch in
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: ch.characterId))
|
||||
onSelectCharacter(ch.characterId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +41,7 @@ struct CharacterView: View {
|
||||
title: "신규 캐릭터",
|
||||
items: viewModel.newCharacters
|
||||
) { ch in
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: ch.characterId))
|
||||
onSelectCharacter(ch.characterId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +54,7 @@ struct CharacterView: View {
|
||||
title: section.title,
|
||||
items: section.characters
|
||||
) { ch in
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: ch.characterId))
|
||||
onSelectCharacter(ch.characterId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,5 +90,5 @@ struct CharacterView: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
CharacterView()
|
||||
CharacterView(onSelectCharacter: { _ in })
|
||||
}
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Bootpay
|
||||
import BootpayUI
|
||||
import PopupView
|
||||
|
||||
struct ChatTabView: View {
|
||||
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
|
||||
@AppStorage("auth") private var auth: Bool = UserDefaults.bool(forKey: UserDefaultsKey.auth)
|
||||
|
||||
private enum InnerTab: Int, CaseIterable {
|
||||
case character = 0
|
||||
@@ -23,6 +27,25 @@ struct ChatTabView: View {
|
||||
}
|
||||
|
||||
@State private var selectedTab: InnerTab = .character
|
||||
@State private var isShowAuthView: Bool = false
|
||||
@State private var pendingCharacterId: Int? = nil
|
||||
@State private var payload = Payload()
|
||||
|
||||
// CharacterView에서 전달받는 단일 진입 함수
|
||||
private func handleCharacterSelection(_ characterId: Int) {
|
||||
let trimmed = token.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else {
|
||||
AppState.shared.setAppStep(step: .login)
|
||||
return
|
||||
}
|
||||
if auth == false {
|
||||
// 본인인증 전체화면 표시 후 완료 시 바로 이동
|
||||
pendingCharacterId = characterId
|
||||
isShowAuthView = true
|
||||
return
|
||||
}
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
@@ -70,13 +93,46 @@ struct ChatTabView: View {
|
||||
Group {
|
||||
switch selectedTab {
|
||||
case .character:
|
||||
CharacterView()
|
||||
CharacterView(onSelectCharacter: handleCharacterSelection)
|
||||
case .talk:
|
||||
TalkView()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
.onAppear {
|
||||
payload.applicationId = BOOTPAY_APP_ID
|
||||
payload.price = 0
|
||||
payload.pg = "다날"
|
||||
payload.method = "본인인증"
|
||||
payload.orderName = "본인인증"
|
||||
payload.authenticationId = "\(UserDefaults.string(forKey: .nickname))__\(String(NSTimeIntervalSince1970))"
|
||||
}
|
||||
.fullScreenCover(isPresented: $isShowAuthView) {
|
||||
BootpayUI(payload: payload, requestType: BootpayRequest.TYPE_AUTHENTICATION)
|
||||
.onConfirm { _ in
|
||||
true
|
||||
}
|
||||
.onCancel { _ in
|
||||
isShowAuthView = false
|
||||
}
|
||||
.onError { _ in
|
||||
AppState.shared.errorMessage = "본인인증 중 오류가 발생했습니다."
|
||||
AppState.shared.isShowErrorPopup = true
|
||||
isShowAuthView = false
|
||||
}
|
||||
.onDone { _ in
|
||||
auth = true
|
||||
isShowAuthView = false
|
||||
if let chId = pendingCharacterId {
|
||||
pendingCharacterId = nil
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: chId))
|
||||
}
|
||||
}
|
||||
.onClose {
|
||||
isShowAuthView = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -276,6 +276,23 @@ struct ContentView: View {
|
||||
self.isShowDialog = true
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $appState.isShowErrorPopup, type: .toast, position: .top, autohideIn: 1) {
|
||||
GeometryReader { geo in
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(appState.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user