Skip to content

Commit d71ed57

Browse files
stephencelismluisbrown
authored andcommitted
Cleanup
1 parent b4fe7be commit d71ed57

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Examples/Todos/Todos/Todos.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ let appReducer = Reducer<AppState, AppAction, AppEnvironment>.combine(
6666
state.filter = filter
6767
return .none
6868

69-
case let .move(source, destination):
70-
// Get source and destination in unfiltered todos array
71-
let sourceInTodos = source
72-
.map { state.filteredTodos[$0] }
73-
.compactMap { state.todos.index(id: $0.id) }
74-
let destinationInTodos = state.todos.index(id: state.filteredTodos[destination].id)!
75-
76-
state.todos.move(fromOffsets: IndexSet(sourceInTodos), toOffset: destinationInTodos)
69+
case var .move(source, destination):
70+
if state.filter != .all {
71+
source = IndexSet(
72+
source
73+
.map { state.filteredTodos[$0] }
74+
.compactMap { state.todos.index(id: $0.id) }
75+
)
76+
destination = state.todos.index(id: state.filteredTodos[destination].id)
77+
?? destination
78+
}
79+
80+
state.todos.move(fromOffsets: source, toOffset: destination)
81+
7782
return Effect(value: .sortCompletedTodos)
7883
.delay(0.1, on: environment.mainQueue)
7984

0 commit comments

Comments
 (0)