First load labels from cache then make call

Also sorts them alphabetically.
This commit is contained in:
Jackson Harper
2022-12-22 16:01:18 +08:00
parent 9e35fee17c
commit 4298183a24

View File

@ -23,16 +23,22 @@ import Views
) async {
isLoading = true
if let labelIDs = try? await dataService.labels() {
dataService.viewContext.performAndWait {
setLabels(labelIDs.compactMap { dataService.viewContext.object(with: $0) as? LinkedItemLabel })
}
let selLabels = initiallySelectedLabels ?? item?.sortedLabels ?? []
for label in labels {
if selLabels.contains(label) {
selectedLabels.append(label)
} else {
unselectedLabels.append(label)
await loadLabelsFromStore(dataService: dataService)
Task.detached(priority: .userInitiated) {
if let labelIDs = try? await dataService.labels() {
DispatchQueue.main.async {
dataService.viewContext.performAndWait {
self.setLabels(labelIDs.compactMap { dataService.viewContext.object(with: $0) as? LinkedItemLabel })
}
let selLabels = initiallySelectedLabels ?? item?.sortedLabels ?? []
for label in self.labels {
if selLabels.contains(label) {
self.selectedLabels.append(label)
} else {
self.unselectedLabels.append(label)
}
}
}
}
}