diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift index 9b2dd7335..d2227a3ed 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/ApplyLabelsView.swift @@ -93,7 +93,7 @@ struct ApplyLabelsView: View { } } .onAppear { - viewModel.loadLabelForItem(item: item, dataService: dataService) + viewModel.loadLabels(dataService: dataService, item: item) } } } diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift index d727f5a32..e89c6144f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift @@ -41,7 +41,7 @@ struct LabelsView: View { .listStyle(InsetListStyle()) #endif } - .onAppear { viewModel.loadLabels(dataService: dataService) } + .onAppear { viewModel.loadLabels(dataService: dataService, item: nil) } } private var innerBody: some View { diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift index 8825a8cd7..b38109c72 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift @@ -14,31 +14,22 @@ final class LabelsViewModel: ObservableObject { var subscriptions = Set() - func loadLabels(dataService: DataService) { + func loadLabels(dataService: DataService, item: FeedItem?) { guard !hasLoadedInitialLabels else { return } isLoading = true - dataService.labelsPublisher().sink( - receiveCompletion: { _ in }, - receiveValue: { [weak self] result in - self?.isLoading = false - self?.labels = result - self?.hasLoadedInitialLabels = true - } - ) - .store(in: &subscriptions) - } - - func loadLabelForItem(item: FeedItem, dataService: DataService) { - guard !hasLoadedInitialLabels else { return } - dataService.labelsPublisher().sink( receiveCompletion: { _ in }, receiveValue: { [weak self] allLabels in self?.isLoading = false + self?.labels = allLabels self?.hasLoadedInitialLabels = true - self?.selectedLabelsForItemInContext = item.labels - self?.unselectedLabelsForItemInContext = allLabels.filter { !item.labels.contains($0) } + if let item = item { + self?.selectedLabelsForItemInContext = item.labels + self?.unselectedLabelsForItemInContext = allLabels.filter { label in + !item.labels.contains(where: { $0.id == label.id }) + } + } } ) .store(in: &subscriptions)