-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainTabPath.swift
More file actions
234 lines (207 loc) ยท 12 KB
/
MainTabPath.swift
File metadata and controls
234 lines (207 loc) ยท 12 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//
// MainTabPath.swift
// App
//
// Created by ๊น๋ฏผํธ on 7/29/24.
//
import Foundation
import ComposableArchitecture
import FeatureSetting
import FeatureCategoryDetail
import FeatureCategorySetting
import FeatureContentDetail
import FeatureContentSetting
import FeatureContentList
import Domain
import Util
@Reducer
public struct MainTabPath {
@ObservableState
public enum State: Equatable {
case ์๋ฆผํจ(PokitAlertBoxFeature.State)
case ๊ฒ์(PokitSearchFeature.State)
case ์ค์ (PokitSettingFeature.State)
case ํฌํท์ถ๊ฐ๋ฐ์์ (PokitCategorySettingFeature.State)
case ๋งํฌ์ถ๊ฐ๋ฐ์์ (ContentSettingFeature.State)
case ์นดํ
๊ณ ๋ฆฌ์์ธ(CategoryDetailFeature.State)
case ๋งํฌ๋ชฉ๋ก(ContentListFeature.State)
}
public enum Action {
case ์๋ฆผํจ(PokitAlertBoxFeature.Action)
case ๊ฒ์(PokitSearchFeature.Action)
case ์ค์ (PokitSettingFeature.Action)
case ํฌํท์ถ๊ฐ๋ฐ์์ (PokitCategorySettingFeature.Action)
case ๋งํฌ์ถ๊ฐ๋ฐ์์ (ContentSettingFeature.Action)
case ์นดํ
๊ณ ๋ฆฌ์์ธ(CategoryDetailFeature.Action)
case ๋งํฌ๋ชฉ๋ก(ContentListFeature.Action)
}
public var body: some Reducer<State, Action> {
Scope(state: \.์๋ฆผํจ, action: \.์๋ฆผํจ) { PokitAlertBoxFeature() }
Scope(state: \.๊ฒ์, action: \.๊ฒ์) { PokitSearchFeature() }
Scope(state: \.์ค์ , action: \.์ค์ ) { PokitSettingFeature() }
Scope(state: \.ํฌํท์ถ๊ฐ๋ฐ์์ , action: \.ํฌํท์ถ๊ฐ๋ฐ์์ ) { PokitCategorySettingFeature() }
Scope(state: \.๋งํฌ์ถ๊ฐ๋ฐ์์ , action: \.๋งํฌ์ถ๊ฐ๋ฐ์์ ) { ContentSettingFeature() }
Scope(state: \.์นดํ
๊ณ ๋ฆฌ์์ธ, action: \.์นดํ
๊ณ ๋ฆฌ์์ธ) { CategoryDetailFeature() }
Scope(state: \.๋งํฌ๋ชฉ๋ก, action: \.๋งํฌ๋ชฉ๋ก) { ContentListFeature() }
}
}
public extension MainTabFeature {
var navigationReducer: some Reducer<State, Action> {
Reduce { state, action in
switch action {
/// - ๋ค๋น๊ฒ์ด์
๋ฐ `์๋ฆผ`๋ฒํผ ๋๋ ์ ๋
case .pokit(.delegate(.alertButtonTapped)),
.recommend(.delegate(.์๋ฆผ_๋ฒํผ_๋๋ ์๋)),
.delegate(.์๋ฆผํจ์ด๋):
state.isPushTapped = false
state.path.append(.์๋ฆผํจ(PokitAlertBoxFeature.State()))
return .none
/// - ๋ค๋น๊ฒ์ด์
๋ฐ `๊ฒ์`๋ฒํผ ๋๋ ์ ๋
case .pokit(.delegate(.searchButtonTapped)),
.recommend(.delegate(.๊ฒ์_๋ฒํผ_๋๋ ์๋)):
state.path.append(.๊ฒ์(PokitSearchFeature.State()))
return .none
/// - ๋ค๋น๊ฒ์ด์
๋ฐ `์ค์ `๋ฒํผ ๋๋ ์ ๋
case .pokit(.delegate(.settingButtonTapped)):
state.path.append(.์ค์ (PokitSettingFeature.State()))
return .none
/// - ํฌํท `์์ `๋ฒํผ ๋๋ ์ ๋
case let .pokit(.delegate(.์์ ํ๊ธฐ(category))),
let .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.ํฌํท์์ (category))))):
state.path.append(.ํฌํท์ถ๊ฐ๋ฐ์์ (PokitCategorySettingFeature.State(
type: .์์ ,
category: category
)))
return .none
case .recommend(.delegate(.์ปจํ
์ธ _์ ๊ณ _API_๋ฐ์)):
return .send(.inner(.๋งํฌํ์
_ํ์ฑํ(.report(title: "์ ๊ณ ๊ฐ ์๋ฃ๋์์ต๋๋ค"))))
/// - ํฌํท `์ถ๊ฐ` ๋ฒํผ ๋๋ ์ ๋
case .delegate(.ํฌํท์ถ๊ฐํ๊ธฐ),
.path(.element(_, action: .๋งํฌ์ถ๊ฐ๋ฐ์์ (.delegate(.ํฌํท์ถ๊ฐํ๊ธฐ)))),
.pokit(.delegate(.ํฌํท์ถ๊ฐ_๋ฒํผ_๋๋ ์๋)),
.recommend(.delegate(.ํฌํท_์ถ๊ฐํ๊ธฐ_๋ฒํผ_๋๋ ์๋)):
state.path.append(.ํฌํท์ถ๊ฐ๋ฐ์์ (PokitCategorySettingFeature.State(type: .์ถ๊ฐ)))
return .none
/// - ํฌํท `์ถ๊ฐ` or `์์ `์ด ์ฑ๊ณต์ ์ผ๋ก `์๋ฃ`๋์์ ๋
case .path(.element(_, action: .ํฌํท์ถ๊ฐ๋ฐ์์ (.delegate(.settingSuccess)))):
state.path.removeLast()
switch state.selectedTab {
case .pokit: return .none
case .recommend:
return .send(.recommend(.delegate(.ํฌํท_์ถ๊ฐํ๊ธฐ_์๋ฃ)))
}
/// - ํฌํท ์นดํ
๊ณ ๋ฆฌ ์์ดํ
๋๋ ์ ๋
case let .pokit(.delegate(.categoryTapped(category))):
state.path.append(.์นดํ
๊ณ ๋ฆฌ์์ธ(CategoryDetailFeature.State(category: category)))
return .none
case .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.ํฌํท์ญ์ )))):
/// Todo: id๊ฐ์ ๋ฐ์์ ์ญ์ API ๋ณด๋ด๊ธฐ
state.path.removeLast()
return .none
/// - ๋งํฌ ์์ธ
case let .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.contentItemTapped(content))))),
let .pokit(.delegate(.contentDetailTapped(content))),
let .path(.element(_, action: .๋งํฌ๋ชฉ๋ก(.delegate(.๋งํฌ์์ธ(content: content))))),
let .path(.element(_, action: .๊ฒ์(.delegate(.linkCardTapped(content: content))))):
state.contentDetail = ContentDetailFeature.State(contentId: content.id)
return .none
/// - ๋งํฌ์์ธ ๋ฐํ
์ํธ์์ ๋งํฌ์์ ์ผ๋ก ์ด๋
case let .contentDetail(.presented(.delegate(.editButtonTapped(id)))),
let .pokit(.delegate(.๋งํฌ์์ ํ๊ธฐ(id))),
let .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.๋งํฌ์์ (id))))),
let .path(.element(_, action: .๋งํฌ๋ชฉ๋ก(.delegate(.๋งํฌ์์ (id))))),
let .path(.element(_, action: .๊ฒ์(.delegate(.๋งํฌ์์ (id))))),
let .path(.element(_, action: .์๋ฆผํจ(.delegate(.moveToContentEdit(id))))):
return .run { send in await send(.inner(.๋งํฌ์ถ๊ฐ๋ฐ์์ ์ด๋(contentId: id))) }
/// - ์ปจํ
์ธ ์์ธ๋ณด๊ธฐ ๋ด๋ถ ์ก์
์คํ
case .contentDetail(.presented(.delegate(.์ฆ๊ฒจ์ฐพ๊ธฐ_๊ฐฑ์ _์๋ฃ))),
.contentDetail(.presented(.delegate(.์ปจํ
์ธ _์กฐํ_์๋ฃ))),
.contentDetail(.presented(.delegate(.์ปจํ
์ธ _์ญ์ _์๋ฃ))):
guard
let stackElementId = state.path.ids.last,
let lastPath = state.path.last
else {
switch state.selectedTab {
case .pokit:
return .send(.pokit(.delegate(.๋ฏธ๋ถ๋ฅ_์นดํ
๊ณ ๋ฆฌ_์ปจํ
์ธ _์กฐํ)))
case .recommend:
return .none
}
}
switch lastPath {
case .๋งํฌ๋ชฉ๋ก:
return .send(.path(.element(id: stackElementId, action: .๋งํฌ๋ชฉ๋ก(.delegate(.์ปจํ
์ธ _๋ชฉ๋ก_์กฐํ)))))
case .๊ฒ์:
return .send(.path(.element(id: stackElementId, action: .๊ฒ์(.delegate(.์ปจํ
์ธ _๊ฒ์)))))
case .์นดํ
๊ณ ๋ฆฌ์์ธ:
return .send(.path(.element(id: stackElementId, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.์นดํ
๊ณ ๋ฆฌ_๋ด_์ปจํ
์ธ _๋ชฉ๋ก_์กฐํ)))))
default: return .none
}
case let .inner(.๋งํฌ์ถ๊ฐ๋ฐ์์ ์ด๋(contentId: id)):
state.categoryId = nil
state.contentDetail = nil
state.path.append(.๋งํฌ์ถ๊ฐ๋ฐ์์ (ContentSettingFeature.State(contentId: id)))
return .none
/// - ๋งํฌ ์ถ๊ฐํ๊ธฐ
case .delegate(.๋งํฌ์ถ๊ฐํ๊ธฐ),
.pokit(.delegate(.๋งํฌ์ถ๊ฐ_๋ฒํผ_๋๋ ์๋)):
state.categoryId = nil
state.path.append(.๋งํฌ์ถ๊ฐ๋ฐ์์ (ContentSettingFeature.State(urlText: state.link)))
state.link = nil
return .none
case let .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.๋งํฌ์ถ๊ฐ(categoryId))))):
state.categoryId = categoryId
state.path.append(.๋งํฌ์ถ๊ฐ๋ฐ์์ (ContentSettingFeature.State()))
return .none
/// - ๋งํฌ์ถ๊ฐ ๋ฐ ์์ ์์ ์ ์ฅํ๊ธฐ ๋๋ ์ ๋
case let .path(.element(stackElementId, action: .๋งํฌ์ถ๊ฐ๋ฐ์์ (.delegate(.์ ์ฅํ๊ธฐ_์๋ฃ(contentId))))):
state.categoryOfSavedContent = contentId
state.path.removeLast()
switch state.path.last {
case .๊ฒ์:
return .merge(
.send(.path(.element(id: stackElementId, action: .๊ฒ์(.delegate(.์ปจํ
์ธ _๊ฒ์))))),
.send(.inner(.๋งํฌํ์
_ํ์ฑํ(.success(title: Constants.๋งํฌ_์ ์ฅ_์๋ฃ_๋ฌธ๊ตฌ, until: 4))), animation: .pokitSpring)
)
default:
return .send(.inner(.๋งํฌํ์
_ํ์ฑํ(.success(title: Constants.๋งํฌ_์ ์ฅ_์๋ฃ_๋ฌธ๊ตฌ, until: 4))), animation: .pokitSpring)
}
case .recommend(.delegate(.์ ์ฅํ๊ธฐ_์๋ฃ)):
return .send(.inner(.๋งํฌํ์
_ํ์ฑํ(.success(title: Constants.๋งํฌ_์ ์ฅ_์๋ฃ_๋ฌธ๊ตฌ, until: 4))), animation: .pokitSpring)
/// - ๊ฐ ํ๋ฉด์์ ๋งํฌ ๋ณต์ฌ ๊ฐ์งํ์ ๋ (๋งํฌ ์ถ๊ฐ ๋ฐ ์์ ํ๋ฉด ์ ์ธ)
case let .path(.element(_, action: .์๋ฆผํจ(.delegate(.linkCopyDetected(url))))),
let .path(.element(_, action: .๊ฒ์(.delegate(.linkCopyDetected(url))))),
let .path(.element(_, action: .์ค์ (.delegate(.linkCopyDetected(url))))),
let .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.linkCopyDetected(url))))),
let .path(.element(_, action: .ํฌํท์ถ๊ฐ๋ฐ์์ (.delegate(.linkCopyDetected(url))))),
let .path(.element(_, action: .๋งํฌ๋ชฉ๋ก(.delegate(.linkCopyDetected(url))))):
return .run { send in await send(.inner(.linkCopySuccess(url)), animation: .pokitSpring) }
/// ๋ฐํ
๋ฉ์ธ์ง
case let .pokit(.delegate(.linkPopup(text))):
state.linkPopup = .text(title: text)
return .none
case .path(.element(_, action: .์ค์ (.delegate(.๋ก๊ทธ์์)))):
return .send(.delegate(.๋ก๊ทธ์์))
case .path(.element(_, action: .์ค์ (.delegate(.ํ์ํํด)))):
return .send(.delegate(.ํ์ํํด))
case .path(.element(_, action: .์๋ฆผํจ(.delegate(.alertBoxDismiss)))):
let _ = state.path.popLast()
return .none
/// - ์ด๋ ์๋ฝ ์๋ฃ
case .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.์ด๋_์๋ฝ_์๋ฃ)))):
state.path.removeLast()
return .send(.inner(.๋งํฌํ์
_ํ์ฑํ(.success(title: "์ด๋๋ฅผ ์๋ฝํ์ต๋๋ค", until: 2))), animation: .pokitSpring)
/// - ๊ณต์ ํฌํท ์ ์ฅ ์๋ฃ
case .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.์ ์ฅ_์๋ฃ)))):
state.path.removeLast()
return .send(.inner(.๋งํฌํ์
_ํ์ฑํ(.success(title: "ํฌํท์ ์ ์ฅํ์ต๋๋ค", until: 2))), animation: .pokitSpring)
/// - ํฌํท ๋๊ฐ๊ธฐ ์๋ฃ
case .path(.element(_, action: .์นดํ
๊ณ ๋ฆฌ์์ธ(.delegate(.ํฌํท๋๊ฐ๊ธฐ)))):
state.path.removeLast()
return .send(.inner(.๋งํฌํ์
_ํ์ฑํ(.success(title: "ํฌํท์์ ๋๊ฐ์ต๋๋ค", until: 2))), animation: .pokitSpring)
default: return .none
}
}
.forEach(\.path, action: \.path) { MainTabPath() }
}
}