diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index 799146733..7f6893916 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -103,7 +103,7 @@ import Views } } .onChange(of: viewModel.selectedLinkItem) { _ in - viewModel.commitProgressUpdates() + viewModel.commitItemUpdates() } } } diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index 763615607..4ee67a777 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -11,6 +11,9 @@ final class HomeFeedViewModel: ObservableObject { /// Track progress updates to be committed when user navigates back to grid view var uncommittedReadingProgressUpdates = [String: Double]() + /// Track label updates to be committed when user navigates back to grid view + var uncommittedLabelUpdates = [String: [FeedItemLabel]]() + @Published var items = [FeedItem]() @Published var isLoading = false @Published var showPushNotificationPrimer = false @@ -173,14 +176,18 @@ final class HomeFeedViewModel: ObservableObject { .store(in: &subscriptions) } - /// Update `FeedItem`s with the cached reading progress values so it can animate when the + /// Update `FeedItem`s with the cached reading progress and label values so it can animate when the /// user navigates back to the grid view (and also avoid mutations of the grid items /// that can cause the `NavigationView` to pop. - func commitProgressUpdates() { + func commitItemUpdates() { for (key, value) in uncommittedReadingProgressUpdates { updateProgress(itemID: key, progress: value) } + for (key, value) in uncommittedLabelUpdates { + updateLabels(itemID: key, labels: value) + } uncommittedReadingProgressUpdates = [:] + uncommittedLabelUpdates = [:] } private func updateProgress(itemID: String, progress: Double) { @@ -191,6 +198,13 @@ final class HomeFeedViewModel: ObservableObject { } func updateLabels(itemID: String, labels: [FeedItemLabel]) { + // If item is being being displayed then delay the state update of labels until + // user is no longer reading the item. + if selectedLinkItem != nil { + uncommittedLabelUpdates[itemID] = labels + return + } + guard let item = items.first(where: { $0.id == itemID }) else { return } if let index = items.firstIndex(of: item) { items[index].labels = labels diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index 4759c527b..ecf6144a8 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -132,6 +132,10 @@ import WebKit Menu( content: { Group { + Button( + action: { homeFeedViewModel.itemUnderLabelEdit = item }, + label: { Label("Edit Labels", systemImage: "tag") } + ) Button( action: { homeFeedViewModel.setLinkArchived(