feat(chat): 캐릭터 상세 이동 로직 ChatTabView로 이관 및 로그인/본인인증 처리 추가

This commit is contained in:
Yu Sung
2025-09-08 14:33:06 +09:00
parent 70b7801074
commit 20fa1db718
4 changed files with 84 additions and 6 deletions

View File

@@ -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
}
}
}
}