-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootView.swift
More file actions
101 lines (96 loc) · 3.65 KB
/
Copy pathRootView.swift
File metadata and controls
101 lines (96 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// RootView.swift
// DevLogPresentation
//
// Created by opfic on 5/2/25.
//
import SwiftUI
import Combine
import ComposableArchitecture
import DevLogCore
import DevLogDomain
public struct RootView: View {
@Environment(\.diContainer) var container: DIContainer
@State private var store: StoreOf<RootFeature>
private let widgetURLTab: (URL) -> MainTab?
private let windowEvent: TodoEditorWindowEvent
private let pushNotificationTodoIdPublisher: AnyPublisher<String, Never>
private let clearPushNotificationRoute: () -> Void
public init(
sessionUseCase: ObserveAuthSessionUseCase,
networkConnectivityUseCase: ObserveNetworkConnectivityUseCase,
systemThemeUseCase: ObserveSystemThemeUseCase,
trackAnalyticsEventUseCase: TrackAnalyticsEventUseCase,
widgetURLTab: @escaping (URL) -> MainTab?,
windowEvent: TodoEditorWindowEvent,
pushNotificationTodoIdPublisher: AnyPublisher<String, Never>,
clearPushNotificationRoute: @escaping () -> Void
) {
self._store = State(initialValue: Store(initialState: RootFeature.State()) {
RootFeature()
} withDependencies: {
$0.observeAuthSessionUseCase = sessionUseCase
$0.networkConnectivityUseCase = networkConnectivityUseCase
$0.systemThemeUseCase = systemThemeUseCase
$0.trackAnalyticsEventUseCase = trackAnalyticsEventUseCase
})
self.widgetURLTab = widgetURLTab
self.windowEvent = windowEvent
self.pushNotificationTodoIdPublisher = pushNotificationTodoIdPublisher
self.clearPushNotificationRoute = clearPushNotificationRoute
}
public var body: some View {
ZStack {
Color(UIColor.systemGroupedBackground).ignoresSafeArea()
if let signIn = store.signIn {
if signIn {
MainView(
container: container,
windowEvent: windowEvent,
selectedTab: $store.selectedMainTab
)
} else {
LoginView(signInUseCase: container.resolve(SignInUseCase.self))
}
}
}
.preferredColorScheme(store.theme.colorScheme)
.onAppear { store.send(.onAppear) }
.onOpenURL { url in
guard let mainTab = widgetURLTab(url) else { return }
store.send(.openWidgetRoute(mainTab))
}
.alert($store.scope(state: \.alert, action: \.alert))
.sheet(item: $store.scope(state: \.sheet, action: \.sheet)) { sheetStore in
sheetContent(todoId: sheetStore.todoId) {
sheetStore.send(.tapCloseButton)
}
}
.onReceive(pushNotificationTodoIdPublisher) { todoId in
store.send(.presentTodoDetail(todoId))
clearPushNotificationRoute()
}
}
private func sheetContent(
todoId: String,
onClose: @escaping () -> Void
) -> some View {
NavigationStack {
TodoDetailView(store: Store(
initialState: TodoDetailFeature.State(todoId: todoId, showEditButton: false)
) {
TodoDetailFeature()
} withDependencies: {
$0.fetchTodoByIdUseCase = container.resolve(FetchTodoByIdUseCase.self)
$0.fetchReferenceItemsUseCase = container.resolve(FetchReferenceItemsUseCase.self)
})
.toolbar {
ToolbarLeadingButton {
onClose()
}
}
}
.background(Color(.systemGroupedBackground))
.presentationDragIndicator(.visible)
}
}