Skip to content

Commit c911d77

Browse files
stephencelismluisbrown
authored andcommitted
Todos demo: fix sorting filtered todos (#1404)
* Todos demo: fix sorting filtered todos * wip * Update TodosTests.swift (cherry picked from commit 3ba71b9787d1500fb35a322444cf990c801d5e08)
1 parent 041c72c commit c911d77

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Examples/Todos/Todos/Todos.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ let appReducer = Reducer<AppState, AppAction, AppEnvironment>.combine(
6767
return .none
6868

6969
case var .move(source, destination):
70-
if state.filter != .all {
70+
if state.filter == .completed {
7171
source = IndexSet(
7272
source
7373
.map { state.filteredTodos[$0] }
7474
.compactMap { state.todos.index(id: $0.id) }
7575
)
7676
destination =
77-
state.todos.index(id: state.filteredTodos[destination].id)
77+
(destination < state.filteredTodos.endIndex
78+
? state.todos.index(id: state.filteredTodos[destination].id)
79+
: state.todos.endIndex)
7880
?? destination
7981
}
8082

Examples/Todos/TodosTests/TodosTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ final class TodosTests: XCTestCase {
264264
TodoState(
265265
description: "",
266266
id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!,
267-
isComplete: true
267+
isComplete: false
268268
),
269269
TodoState(
270270
description: "",
271271
id: UUID(uuidString: "00000000-0000-0000-0000-000000000002")!,
272-
isComplete: false
272+
isComplete: true
273273
),
274274
TodoState(
275275
description: "",
@@ -293,12 +293,12 @@ final class TodosTests: XCTestCase {
293293
await store.send(.filterPicked(.completed)) {
294294
$0.filter = .completed
295295
}
296-
await store.send(.move([0], 1)) {
296+
await store.send(.move([0], 2)) {
297297
$0.todos = [
298298
$0.todos[0],
299-
$0.todos[2],
300299
$0.todos[1],
301300
$0.todos[3],
301+
$0.todos[2],
302302
]
303303
}
304304
await self.mainQueue.advance(by: .milliseconds(100))

0 commit comments

Comments
 (0)