message web container view when highlight view is dismissed and mutations have occurred

This commit is contained in:
Satindar Dhillon
2022-10-05 11:25:05 -07:00
parent c5ad8a238c
commit db9246553f
4 changed files with 20 additions and 4 deletions

View File

@ -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

View File

@ -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,

View File

@ -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) {

View File

@ -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())