Skip to content

Commit 47b5f1b

Browse files
committed
Cleanup
1 parent 02cf759 commit 47b5f1b

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
@@ -65,14 +65,19 @@ let appReducer = Reducer<AppState, AppAction, AppEnvironment>.combine(
6565
state.filter = filter
6666
return .none
6767

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

0 commit comments

Comments
 (0)