@@ -172,7 +172,47 @@ struct TodayFeature {
172172 LoadingFeature ( )
173173 }
174174 Reduce { state, action in
175- reduce ( action, state: & state)
175+ switch action {
176+ case . alert:
177+ break
178+ case . refresh, . fetchData:
179+ return fetchTodosEffect ( )
180+ case . setSectionScope( let scope) :
181+ if state. selectedSectionScope == scope, scope != . all {
182+ state. selectedSectionScope = . all
183+ } else {
184+ state. selectedSectionScope = scope
185+ }
186+ case . setDueDateVisibility( let visibility) :
187+ state. displayOptions. dueDateVisibility = visibility
188+ return updateDisplayOptionsEffect ( state. displayOptions)
189+ case . setFocusVisibility( let visibility) :
190+ state. displayOptions. focusVisibility = visibility
191+ return updateDisplayOptionsEffect ( state. displayOptions)
192+ case . resetDisplayOptions:
193+ state. displayOptions = . default
194+ return updateDisplayOptionsEffect ( state. displayOptions)
195+ case . completeTodo( let item) :
196+ return completeTodoEffect ( item)
197+ case . togglePinned( let item) :
198+ return togglePinnedEffect ( item)
199+ case . store( . setAlert) :
200+ state. alert = Self . alertState ( )
201+ case . store( . setTodos( let todos) ) :
202+ state. todos = todos
203+ case . store( . updateTodo( let item) ) :
204+ if let index = state. todos. firstIndex ( where: { $0. id == item. id } ) {
205+ state. todos [ index] = item
206+ } else {
207+ state. todos. append ( item)
208+ }
209+ case . store( . removeTodo( let todoId) ) :
210+ state. todos. removeAll { $0. id == todoId }
211+ case . loading:
212+ break
213+ }
214+
215+ return . none
176216 }
177217 . ifLet ( \. $alert, action: \. alert)
178218 }
@@ -211,53 +251,6 @@ private enum UpdateTodayDisplayOptionsUseCaseKey: DependencyKey {
211251}
212252
213253private extension TodayFeature {
214- func reduce(
215- _ action: Action ,
216- state: inout State
217- ) -> Effect < Action > {
218- switch action {
219- case . alert:
220- break
221- case . refresh, . fetchData:
222- return fetchTodosEffect ( )
223- case . setSectionScope( let scope) :
224- if state. selectedSectionScope == scope, scope != . all {
225- state. selectedSectionScope = . all
226- } else {
227- state. selectedSectionScope = scope
228- }
229- case . setDueDateVisibility( let visibility) :
230- state. displayOptions. dueDateVisibility = visibility
231- return updateDisplayOptionsEffect ( state. displayOptions)
232- case . setFocusVisibility( let visibility) :
233- state. displayOptions. focusVisibility = visibility
234- return updateDisplayOptionsEffect ( state. displayOptions)
235- case . resetDisplayOptions:
236- state. displayOptions = . default
237- return updateDisplayOptionsEffect ( state. displayOptions)
238- case . completeTodo( let item) :
239- return completeTodoEffect ( item)
240- case . togglePinned( let item) :
241- return togglePinnedEffect ( item)
242- case . store( . setAlert) :
243- state. alert = Self . alertState ( )
244- case . store( . setTodos( let todos) ) :
245- state. todos = todos
246- case . store( . updateTodo( let item) ) :
247- if let index = state. todos. firstIndex ( where: { $0. id == item. id } ) {
248- state. todos [ index] = item
249- } else {
250- state. todos. append ( item)
251- }
252- case . store( . removeTodo( let todoId) ) :
253- state. todos. removeAll { $0. id == todoId }
254- case . loading:
255- break
256- }
257-
258- return . none
259- }
260-
261254 func fetchTodosEffect( ) -> Effect < Action > {
262255 . run { [ fetchTodosUseCase] send in
263256 await send ( . loading( . begin( target: . default, mode: . delayed) ) )
0 commit comments