Skip to content

Commit be7f3ca

Browse files
feat: auto-refresh (#37)
* fix: tag and fields not refreshing * fix: tags in tag manager not refreshing
1 parent 72a5bb3 commit be7f3ca

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

LabelWorkshop/views/EntryView.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import Flow
33

44
struct EntryView: View {
55
let entry: Entry
6-
@State var tags: [Tag]
7-
@State var fields: [Field]
6+
@State var tags: [Tag] = []
7+
@State var fields: [Field] = []
88
@State var showTagSelector: Bool = false
99
@State var showFieldTypeSelector: Bool = false
1010

1111
init(entry: Entry) {
1212
self.entry = entry
13-
self.tags = entry.getTags()
14-
self.fields = entry.getFields()
1513
}
1614

1715
var body: some View {
@@ -214,6 +212,9 @@ struct EntryView: View {
214212
}
215213
.tint(.red)
216214
}
215+
}.onAppear {
216+
self.tags = entry.getTags()
217+
self.fields = entry.getFields()
217218
}
218219
}
219220
}

LabelWorkshop/views/TagManagerView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
struct TagManagerView: View {
44
@Environment(\.dismiss) private var dismiss
55
let library: Library
6+
@State var tags: [Tag] = []
67
@State var showNewTag: Bool = false
78

89
init(library: Library) {
@@ -13,7 +14,7 @@ struct TagManagerView: View {
1314
NavigationView {
1415
ScrollView {
1516
VStack {
16-
ForEach(Tag.fetchAll(library: library), id: \.id){ tag in
17+
ForEach($tags, id: \.id){ $tag in
1718
NavigationLink(destination: TagDetailsView(tag: tag)){
1819
TagView(tag: tag, fullWidth: true)
1920
}
@@ -56,6 +57,8 @@ struct TagManagerView: View {
5657
}
5758
}
5859
}
60+
}.onAppear {
61+
self.tags = Tag.fetchAll(library: library)
5962
}
6063
}
6164
}

0 commit comments

Comments
 (0)