-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Screens.swift
52 lines (45 loc) · 1.24 KB
/
Screens.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Atoms
import SwiftUI
struct TodoListScreen: View {
@Watch(FilteredTodosAtom())
var filteredTodos
@ViewContext
var context
var body: some View {
List {
Section {
TodoStats()
TodoCreator()
}
Section {
TodoFilters()
ForEach(filteredTodos, id: \.id) { todo in
TodoItem(todo: todo)
}
.onDelete { indexSet in
let filtered = filteredTodos
context.modify(TodosAtom()) { todos in
let indices = indexSet.compactMap { index in
todos.firstIndex(of: filtered[index])
}
todos.remove(atOffsets: IndexSet(indices))
}
}
}
}
.navigationTitle("Todo")
#if os(iOS)
.listStyle(.insetGrouped)
.buttonStyle(.borderless)
#elseif !os(tvOS)
.buttonStyle(.borderless)
#endif
}
}
struct TodoListScreen_Preview: PreviewProvider {
static var previews: some View {
AtomRoot {
TodoListScreen()
}
}
}