Skip to content

Commit

Permalink
[Feat] isConnected 관련 AppStorage 추가, 앱 코디네이터 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
FpRaArNkK committed Feb 12, 2025
1 parent a319264 commit 55812a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions TnT/Projects/Domain/Sources/Policy/AppStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import Foundation

public enum AppStorage {
public static let hideHomePopupUntil: String = "hideHomePopupUntil"
public static let isConnected: String = "isConnected"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public struct AppFlowCoordinatorFeature {
@ObservableState
public struct State: Equatable {
// MARK: Data related state
/// 트레이너/트레이니 연결 여부
@Shared(.appStorage(AppStorage.isConnected)) var isConnected: Bool = false
/// 유저 멤버 유형
var userType: UserType?
// MARK: UI related state
/// 스플래시 표시 여부
var view_isSplashActive: Bool
/// 팝업 표시 여부
var view_isPopUpPresented: Bool

// MARK: SubFeature state
Expand Down Expand Up @@ -59,7 +64,7 @@ public struct AppFlowCoordinatorFeature {
/// 저장 세션 정보 확인
case checkSessionInfo
/// 현재 유저 정보 업데이트
case updateUserInfo(UserType?)
case updateUserInfo(type: UserType?, isConnected: Bool)
/// 스플래시 표시 종료 시
case splashFinished
/// 세션 만료 팝업 표시
Expand Down Expand Up @@ -139,15 +144,20 @@ public struct AppFlowCoordinatorFeature {
switch action {
case .checkSession:
return .run { send in
let result = try? await userUseCaseRepo.getSessionCheck()
switch result?.memberType {
guard let result = try? await userUseCaseRepo.getSessionCheck() else {
try keyChainManager.delete(.sessionId)
await send(.updateUserInfo(type: nil, isConnected: false))
return
}

switch result.memberType {
case .trainer:
await send(.updateUserInfo(.trainer))
await send(.updateUserInfo(type: .trainer, isConnected: result.isConnected))
case .trainee:
await send(.updateUserInfo(.trainee))
await send(.updateUserInfo(type: .trainee, isConnected: result.isConnected))
default:
try keyChainManager.delete(.sessionId)
await send(.updateUserInfo(nil))
await send(.updateUserInfo(type: nil, isConnected: false))
}
}
}
Expand All @@ -156,9 +166,11 @@ public struct AppFlowCoordinatorFeature {
let session: String? = try? keyChainManager.read(for: .sessionId)
return session != nil
? .send(.api(.checkSession))
: .send(.updateUserInfo(nil))
: .send(.updateUserInfo(type: nil, isConnected: false))

case let .updateUserInfo(userType, isConnected):
state.$isConnected.withLock { $0 = isConnected }

case .updateUserInfo(let userType):
switch userType {
case .trainee:
return self.setFlow(.traineeMainFlow, state: &state)
Expand Down

0 comments on commit 55812a1

Please sign in to comment.