-
Notifications
You must be signed in to change notification settings - Fork 0
[#582] RootView에 TCA를 적용한다 #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ad55cb1
feat: store 1차 구현
opficdev 93ed007
refactor: AlertState 적용
opficdev a1efe58
refactor: SheetState 적용
opficdev 5b505a2
refactor: RootFeature BindingAction 적용
opficdev c8e3dfb
refactor: RootFeature 뷰 스토어 액션 분리 제거
opficdev 3fbfb24
refactor: sheetContent 분리
opficdev 3170a0f
chore: 불필요 뷰모델 파일 및 참조 제거
opficdev 73416b5
refactor: 불필요 receive(on:) 제거
opficdev 45e9d6c
refactor: 옵셔널 주입 제거
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
201 changes: 201 additions & 0 deletions
201
Application/DevLogPresentation/Sources/Root/RootFeature.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| // | ||
| // RootFeature.swift | ||
| // DevLogPresentation | ||
| // | ||
| // Created by opfic on 6/17/26. | ||
| // | ||
|
|
||
| import Combine | ||
| import ComposableArchitecture | ||
| import DevLogCore | ||
| import DevLogDomain | ||
| import Foundation | ||
|
|
||
| @Reducer | ||
| struct RootFeature { | ||
| private enum CancelID: Hashable { | ||
| case networkConnectivity | ||
| case session | ||
| case theme | ||
| } | ||
|
|
||
| @ObservableState | ||
| struct State: Equatable { | ||
| @Presents var alert: AlertState<Never>? | ||
| @Presents var sheet: SheetState? | ||
| var isNetworkConnected = true | ||
| var signIn: Bool? | ||
| var theme: SystemTheme = .automatic | ||
| var selectedMainTab = MainTab.home | ||
| var isObservingNetworkConnectivity = false | ||
| var isObservingSession = false | ||
| var isObservingTheme = false | ||
| } | ||
|
|
||
| @ObservableState | ||
| struct SheetState: Equatable, Identifiable { | ||
| let todoId: String | ||
| var id: String { todoId } | ||
| } | ||
|
|
||
| enum Action: BindableAction, Equatable { | ||
| case alert(PresentationAction<Never>) | ||
| case binding(BindingAction<State>) | ||
| case sheet(PresentationAction<Sheet>) | ||
| case onAppear | ||
| case presentTodoDetail(String) | ||
| case openWidgetRoute(MainTab) | ||
| case networkStatusChanged(Bool) | ||
| case setTheme(SystemTheme) | ||
| case didLogined(Bool) | ||
|
|
||
| enum Sheet: Equatable { | ||
| case tapCloseButton | ||
| } | ||
| } | ||
|
|
||
| @Dependency(\.observeAuthSessionUseCase) var observeAuthSessionUseCase | ||
| @Dependency(\.networkConnectivityUseCase) var networkConnectivityUseCase | ||
| @Dependency(\.systemThemeUseCase) var systemThemeUseCase | ||
| @Dependency(\.trackAnalyticsEventUseCase) var trackAnalyticsEventUseCase | ||
| @Dependency(\.setApplicationBadgeCount) var setApplicationBadgeCount | ||
|
|
||
| var body: some ReducerOf<Self> { | ||
| BindingReducer() | ||
| Reduce { state, action in | ||
| switch action { | ||
| case .alert: | ||
| break | ||
| case .binding: | ||
| break | ||
| case .sheet(.dismiss), .sheet(.presented(.tapCloseButton)): | ||
| state.sheet = nil | ||
| case .sheet: | ||
| break | ||
| case .onAppear: | ||
| var effect = clearApplicationBadgeCountEffect() | ||
|
|
||
| if !state.isObservingNetworkConnectivity { | ||
| state.isObservingNetworkConnectivity = true | ||
| effect = .merge(effect, observeNetworkConnectivityEffect()) | ||
| } | ||
|
|
||
| if !state.isObservingSession { | ||
| state.isObservingSession = true | ||
| effect = .merge(effect, observeSessionEffect()) | ||
| } | ||
|
|
||
| if !state.isObservingTheme { | ||
| state.isObservingTheme = true | ||
| effect = .merge(effect, observeThemeEffect()) | ||
| } | ||
|
|
||
| return effect | ||
| case .presentTodoDetail(let todoId): | ||
| state.sheet = .init(todoId: todoId) | ||
| case .openWidgetRoute(let mainTab): | ||
| guard state.signIn == true else { break } | ||
| state.selectedMainTab = mainTab | ||
| case .networkStatusChanged(let isConnected): | ||
| let wasConnected = state.isNetworkConnected | ||
| state.isNetworkConnected = isConnected | ||
| if wasConnected && !isConnected { | ||
| state.alert = Self.alertState() | ||
| } | ||
| case .setTheme(let theme): | ||
| state.theme = theme | ||
| case .didLogined(let result): | ||
| state.signIn = result | ||
| if result { | ||
| state.selectedMainTab = .home | ||
| } else { | ||
| return trackLoginScreenEffect() | ||
| } | ||
| } | ||
|
|
||
| return .none | ||
| } | ||
| .ifLet(\.$alert, action: \.alert) | ||
| .ifLet(\.$sheet, action: \.sheet) { | ||
| RootSheetFeature() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private struct RootSheetFeature: Reducer { | ||
| typealias State = RootFeature.SheetState | ||
| typealias Action = RootFeature.Action.Sheet | ||
|
|
||
| var body: some ReducerOf<Self> { | ||
| EmptyReducer() | ||
| } | ||
| } | ||
|
|
||
| extension DependencyValues { | ||
| var observeAuthSessionUseCase: ObserveAuthSessionUseCase { | ||
| get { self[ObserveAuthSessionUseCaseKey.self] } | ||
| set { self[ObserveAuthSessionUseCaseKey.self] = newValue } | ||
| } | ||
| } | ||
|
|
||
| private enum ObserveAuthSessionUseCaseKey: DependencyKey { | ||
| static var liveValue: ObserveAuthSessionUseCase { | ||
| preconditionFailure("ObserveAuthSessionUseCase must be provided.") | ||
| } | ||
|
|
||
| static var testValue: ObserveAuthSessionUseCase { | ||
| liveValue | ||
| } | ||
| } | ||
|
|
||
| private extension RootFeature { | ||
| func clearApplicationBadgeCountEffect() -> Effect<Action> { | ||
| .run { [setApplicationBadgeCount] _ in | ||
| try? await setApplicationBadgeCount(0) | ||
| } | ||
| } | ||
|
|
||
| func observeNetworkConnectivityEffect() -> Effect<Action> { | ||
| .publisher { [networkConnectivityUseCase] in | ||
| networkConnectivityUseCase.observe() | ||
| .map(Action.networkStatusChanged) | ||
| } | ||
| .cancellable(id: CancelID.networkConnectivity, cancelInFlight: true) | ||
| } | ||
|
opficdev marked this conversation as resolved.
|
||
|
|
||
| func observeSessionEffect() -> Effect<Action> { | ||
| .publisher { [observeAuthSessionUseCase] in | ||
| observeAuthSessionUseCase.observe() | ||
| .removeDuplicates() | ||
| .map(Action.didLogined) | ||
| } | ||
| .cancellable(id: CancelID.session, cancelInFlight: true) | ||
| } | ||
|
opficdev marked this conversation as resolved.
|
||
|
|
||
| func observeThemeEffect() -> Effect<Action> { | ||
| .publisher { [systemThemeUseCase] in | ||
| systemThemeUseCase.observe() | ||
| .removeDuplicates() | ||
| .map(Action.setTheme) | ||
| } | ||
| .cancellable(id: CancelID.theme, cancelInFlight: true) | ||
| } | ||
|
opficdev marked this conversation as resolved.
|
||
|
|
||
| func trackLoginScreenEffect() -> Effect<Action> { | ||
| .run { [trackAnalyticsEventUseCase] _ in | ||
| trackAnalyticsEventUseCase?.execute(.screenView("login")) | ||
| } | ||
| } | ||
|
opficdev marked this conversation as resolved.
|
||
|
|
||
| static func alertState() -> AlertState<Never> { | ||
| AlertState { | ||
| TextState(String(localized: "root_network_disconnected_title")) | ||
| } actions: { | ||
| ButtonState(role: .cancel) { | ||
| TextState(String(localized: "common_close")) | ||
| } | ||
| } message: { | ||
| TextState(String(localized: "root_network_disconnected_message")) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.