From db9246553fb121c394cef06928a82e48a1d48d07 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Wed, 5 Oct 2022 11:25:05 -0700 Subject: [PATCH] message web container view when highlight view is dismissed and mutations have occurred --- .../App/Views/Highlights/HighlightsListCard.swift | 2 ++ .../App/Views/Highlights/HighlightsListView.swift | 6 +++++- .../Sources/App/Views/Home/HomeFeedViewIOS.swift | 3 ++- .../App/Views/WebReader/WebReaderContainer.swift | 13 +++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListCard.swift b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListCard.swift index f488db303..be1857d6f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListCard.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListCard.swift @@ -8,6 +8,7 @@ struct HighlightsListCard: View { @State var showAnnotationModal = false let highlightParams: HighlightListItemParams + @Binding var hasHighlightMutations: Bool let onSaveAnnotation: (String) -> Void var contextMenuView: some View { @@ -111,6 +112,7 @@ struct HighlightsListCard: View { onSave: { onSaveAnnotation(annotation) showAnnotationModal = false + hasHighlightMutations = true }, onCancel: { showAnnotationModal = false diff --git a/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift index b3c0e848a..ac23279f6 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift @@ -10,12 +10,16 @@ struct HighlightsListView: View { @StateObject var viewModel = HighlightsListViewModel() let itemObjectID: NSManagedObjectID + @Binding var hasHighlightMutations: Bool var innerBody: some View { List { Section { ForEach(viewModel.highlightItems) { highlightParams in - HighlightsListCard(highlightParams: highlightParams) { newAnnotation in + HighlightsListCard( + highlightParams: highlightParams, + hasHighlightMutations: $hasHighlightMutations + ) { newAnnotation in viewModel.updateAnnotation( highlightID: highlightParams.highlightID, annotation: newAnnotation, diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index 85cb7c15b..b7d1cfa21 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -11,6 +11,7 @@ import Views private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone struct HomeFeedContainerView: View { + @State var hasHighlightMutations = false @EnvironmentObject var dataService: DataService @EnvironmentObject var audioController: AudioController @@ -63,7 +64,7 @@ import Views LinkedItemTitleEditView(item: item) } .sheet(item: $viewModel.itemForHighlightsView) { item in - HighlightsListView(itemObjectID: item.objectID) + HighlightsListView(itemObjectID: item.objectID, hasHighlightMutations: $hasHighlightMutations) } .toolbar { ToolbarItem(placement: .barTrailing) { diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index a005c3808..11b7e0717 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -13,6 +13,7 @@ struct WebReaderContainerView: View { @State private var showLabelsModal = false @State private var showTitleEdit = false @State private var showHighlightsView = false + @State private var hasPerformedHighlightMutations = false @State var showHighlightAnnotationModal = false @State var safariWebLink: SafariWebLink? @State private var navBarVisibilityRatio = 1.0 @@ -44,6 +45,11 @@ struct WebReaderContainerView: View { } } + func onHighlightListViewDismissal() { + print("has mutations: \(hasPerformedHighlightMutations)") + hasPerformedHighlightMutations = false + } + private func handleHighlightAction(message: WKScriptMessage) { guard let messageBody = message.body as? [String: String] else { return } guard let actionID = messageBody["actionID"] else { return } @@ -203,8 +209,11 @@ struct WebReaderContainerView: View { .sheet(isPresented: $showTitleEdit) { LinkedItemTitleEditView(item: item) } - .sheet(isPresented: $showHighlightsView) { - HighlightsListView(itemObjectID: item.objectID) + .sheet(isPresented: $showHighlightsView, onDismiss: onHighlightListViewDismissal) { + HighlightsListView( + itemObjectID: item.objectID, + hasHighlightMutations: $hasPerformedHighlightMutations + ) } #if os(macOS) .buttonStyle(PlainButtonStyle())