mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix filter application
This commit is contained in:
parent
e9589fd7f3
commit
8329cc166c
3 changed files with 10 additions and 19 deletions
|
|
@ -93,7 +93,7 @@ struct ApplyLabelsView: View {
|
|||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.loadLabelForItem(item: item, dataService: dataService)
|
||||
viewModel.loadLabels(dataService: dataService, item: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -14,31 +14,22 @@ final class LabelsViewModel: ObservableObject {
|
|||
|
||||
var subscriptions = Set<AnyCancellable>()
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue