Improve loading of labels view

This commit is contained in:
Jackson Harper 2023-11-15 11:09:16 +08:00
parent d33c975ffb
commit d270bd685f
2 changed files with 15 additions and 25 deletions

View file

@ -104,24 +104,6 @@ struct ApplyLabelsView: View {
}
.navigationTitle(mode.navTitle)
.background(Color.extensionBackground)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
cancelButton
}
ToolbarItem(placement: .navigationBarTrailing) {
saveItemChangesButton
}
}
#else
.toolbar {
ToolbarItemGroup {
cancelButton
saveItemChangesButton
}
}
#endif
.sheet(isPresented: $viewModel.showCreateLabelModal) {
CreateLabelView(viewModel: viewModel, newLabelName: viewModel.labelSearchFilter)
}
@ -181,14 +163,25 @@ struct ApplyLabelsView: View {
Group {
#if os(iOS)
NavigationView {
if viewModel.labels.isEmpty, viewModel.isLoading {
EmptyView()
} else {
innerBody
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
cancelButton
}
ToolbarItem(placement: .navigationBarTrailing) {
saveItemChangesButton
}
}
}
#elseif os(macOS)
innerBody
.toolbar {
ToolbarItemGroup {
cancelButton
saveItemChangesButton
}
}
.frame(minWidth: 400, minHeight: 600)
#endif
}

View file

@ -29,7 +29,6 @@ import SwiftUI
highlight: Highlight? = nil,
initiallySelectedLabels: [LinkedItemLabel]? = nil
) async {
isLoading = true
let selLabels = initiallySelectedLabels ?? item?.sortedLabels ?? highlight?.sortedLabels ?? []
await loadLabelsFromStore(dataService: dataService)
@ -42,7 +41,6 @@ import SwiftUI
unselectedLabels.insert(label)
}
}
isLoading = false
Task.detached(priority: .userInitiated) {
if let labelIDs = try? await dataService.labels() {
@ -59,7 +57,6 @@ import SwiftUI
self.unselectedLabels.insert(label)
}
}
self.isLoading = false
}
}
}