|
| 1 | +// |
| 2 | +// AppFlowCoordinatorFeature.swift |
| 3 | +// Presentation |
| 4 | +// |
| 5 | +// Created by 박민서 on 2/4/25. |
| 6 | +// Copyright © 2025 yapp25thTeamTnT. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import SwiftUI |
| 10 | +import ComposableArchitecture |
| 11 | + |
| 12 | +import Domain |
| 13 | + |
| 14 | +@Reducer |
| 15 | +public struct AppFlowCoordinatorFeature { |
| 16 | + @ObservableState |
| 17 | + public struct State: Equatable { |
| 18 | + var userType: UserType? |
| 19 | + |
| 20 | + // MARK: SubFeature state |
| 21 | + var trainerMainState: TrainerMainFlowFeature.State? |
| 22 | + var traineeMainState: TraineeMainFlowFeature.State? |
| 23 | + var onboardingState: OnboardingFlowFeature.State? |
| 24 | + |
| 25 | + public init( |
| 26 | + userType: UserType? = nil, |
| 27 | + onboardingState: OnboardingFlowFeature.State? = .init(), |
| 28 | + trainerMainState: TrainerMainFlowFeature.State? = nil, |
| 29 | + traineeMainState: TraineeMainFlowFeature.State? = nil |
| 30 | + ) { |
| 31 | + self.userType = userType |
| 32 | + self.onboardingState = onboardingState |
| 33 | + self.trainerMainState = trainerMainState |
| 34 | + self.traineeMainState = traineeMainState |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + public enum Action { |
| 39 | + /// 하위 코디네이터에서 일어나는 액션을 처리합니다 |
| 40 | + case subFeature(SubFeatureAction) |
| 41 | + case onAppear |
| 42 | + |
| 43 | + @CasePathable |
| 44 | + public enum SubFeatureAction: Sendable { |
| 45 | + /// 온보딩 플로우 코디네이터에서 발생하는 액션 처리 |
| 46 | + case onboardingFlow(OnboardingFlowFeature.Action) |
| 47 | + /// 트레이너 메인탭 플로우 코디네이터에서 발생하는 액션 처리 |
| 48 | + case trainerMainFlow(TrainerMainFlowFeature.Action) |
| 49 | + /// 트레이니 메인탭 플로우 코디네이터에서 발생하는 액션 처리 |
| 50 | + case traineeMainFlow(TraineeMainFlowFeature.Action) |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public init() {} |
| 55 | + |
| 56 | + public var body: some Reducer<State, Action> { |
| 57 | + Reduce { state, action in |
| 58 | + switch action { |
| 59 | + case .subFeature(let internalAction): |
| 60 | + switch internalAction { |
| 61 | + case .onboardingFlow: |
| 62 | + return .none |
| 63 | + |
| 64 | + case .trainerMainFlow: |
| 65 | + return .none |
| 66 | + |
| 67 | + case .traineeMainFlow: |
| 68 | + return .none |
| 69 | + } |
| 70 | + |
| 71 | + case .onAppear: |
| 72 | + return .none |
| 73 | + } |
| 74 | + } |
| 75 | + .ifLet(\.onboardingState, action: \.subFeature.onboardingFlow) { OnboardingFlowFeature() } |
| 76 | + .ifLet(\.trainerMainState, action: \.subFeature.trainerMainFlow) { TrainerMainFlowFeature() } |
| 77 | + .ifLet(\.traineeMainState, action: \.subFeature.traineeMainFlow) { TraineeMainFlowFeature() } |
| 78 | + } |
| 79 | +} |
0 commit comments