-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToDoListView.swift
49 lines (45 loc) · 1.44 KB
/
ToDoListView.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
import SwiftUI
struct ToDoListView: View {
@StateObject var viewModel = ToDoListViewViewModel()
@FirestoreQuery var items: [ToDoListItem]
init(userId: String) {
self._items = FirestoreQuery(
collecttionPath: "users/\(userId)/todos"
)
self._viewModel = StateObject(
wrappedValue: ToDoListViewViewModel(userId: userId)
)
}
var body: some View {
Navigation {
VStack {
List(items) {item in
ToDoListItemView(item: item)
.swipeActions {
Button ("Delete") {
viewModel.delete(id: item.id)
}
.tint(.red)
}
}
.listStyle(PlainListStyle())
}
.navigationTitle("To Do List")
.toolBar {
Button {
viewModel.showingNewItemView = true
} label: {
Image(systemName: "plus")
}
}
.sheet(isPresented: $viewModel.showingNewItemView) {
NewItemView(newItemPresented:$viewModel.showingNewItemView)
}
}
}
}
struct ToDoListItemsView_Previews: PreviewProvider {
static var previews: some View {
ToDoListView(userId: "do not have as did not have new pc at this time ")
}
}