Skip to content

Commit 3ba71b9

Browse files
authored
Todos demo: fix sorting filtered todos (pointfreeco#1404)
* Todos demo: fix sorting filtered todos * wip * Update TodosTests.swift
1 parent 06d4d6e commit 3ba71b9

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
@@ -66,14 +66,16 @@ let appReducer = Reducer<AppState, AppAction, AppEnvironment>.combine(
6666
return .none
6767

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

Examples/Todos/TodosTests/TodosTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ final class TodosTests: XCTestCase {
263263
TodoState(
264264
description: "",
265265
id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!,
266-
isComplete: true
266+
isComplete: false
267267
),
268268
TodoState(
269269
description: "",
270270
id: UUID(uuidString: "00000000-0000-0000-0000-000000000002")!,
271-
isComplete: false
271+
isComplete: true
272272
),
273273
TodoState(
274274
description: "",
@@ -292,12 +292,12 @@ final class TodosTests: XCTestCase {
292292
await store.send(.filterPicked(.completed)) {
293293
$0.filter = .completed
294294
}
295-
await store.send(.move([0], 1)) {
295+
await store.send(.move([0], 2)) {
296296
$0.todos = [
297297
$0.todos[0],
298-
$0.todos[2],
299298
$0.todos[1],
300299
$0.todos[3],
300+
$0.todos[2],
301301
]
302302
}
303303
await self.mainQueue.advance(by: .milliseconds(100))

0 commit comments

Comments
 (0)