From 05574a640eab2b3b8c4e8c22f505f11e417e487c Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Wed, 27 Apr 2022 17:12:27 -0700 Subject: [PATCH] remove performActionSubject from web wrapper view model --- .../App/Views/LinkItemDetailView.swift | 12 +---- .../Views/Article/WebAppWrapperView.swift | 52 +++++++------------ 2 files changed, 21 insertions(+), 43 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index f478035a8..ec06cdbfb 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -76,21 +76,11 @@ enum PDFProvider { queryParams: ["isAppEmbedView": "true", "highlightBarDisabled": isMacApp ? "false" : "true"] ) - let newWebAppWrapperViewModel = WebAppWrapperViewModel( + webAppWrapperViewModel = WebAppWrapperViewModel( webViewURLRequest: urlRequest, baseURL: baseURL, rawAuthCookie: rawAuthCookie ) - - newWebAppWrapperViewModel.performActionSubject.sink { action in - switch action { - case let .shareHighlight(highlightID): - print("show share modal for highlight with id: \(highlightID)") - } - } - .store(in: &newWebAppWrapperViewModel.subscriptions) - - webAppWrapperViewModel = newWebAppWrapperViewModel } } diff --git a/apple/OmnivoreKit/Sources/Views/Article/WebAppWrapperView.swift b/apple/OmnivoreKit/Sources/Views/Article/WebAppWrapperView.swift index 44d0ae7c4..29b3f2f8f 100644 --- a/apple/OmnivoreKit/Sources/Views/Article/WebAppWrapperView.swift +++ b/apple/OmnivoreKit/Sources/Views/Article/WebAppWrapperView.swift @@ -1,4 +1,3 @@ -import Combine import SafariServices import SwiftUI import WebKit @@ -8,8 +7,6 @@ public final class WebAppWrapperViewModel: ObservableObject { case shareHighlight(highlightID: String) } - public var subscriptions = Set() - public let performActionSubject = PassthroughSubject() let webViewURLRequest: URLRequest let baseURL: URL let rawAuthCookie: String? @@ -43,27 +40,25 @@ public struct WebAppWrapperView: View { } public var body: some View { - let webAppView = WebAppView( - request: viewModel.webViewURLRequest, - baseURL: viewModel.baseURL, - rawAuthCookie: viewModel.rawAuthCookie, - openLinkAction: { - #if os(macOS) - NSWorkspace.shared.open($0) - #elseif os(iOS) - safariWebLink = SafariWebLink(id: UUID(), url: $0) - #endif - }, - webViewActionHandler: webViewActionHandler, - navBarVisibilityRatioUpdater: navBarVisibilityRatioUpdater, - annotation: $annotation, - annotationSaveTransactionID: $annotationSaveTransactionID, - sendIncreaseFontSignal: $viewModel.sendIncreaseFontSignal, - sendDecreaseFontSignal: $viewModel.sendDecreaseFontSignal - ) - - return VStack { - webAppView + VStack { + WebAppView( + request: viewModel.webViewURLRequest, + baseURL: viewModel.baseURL, + rawAuthCookie: viewModel.rawAuthCookie, + openLinkAction: { + #if os(macOS) + NSWorkspace.shared.open($0) + #elseif os(iOS) + safariWebLink = SafariWebLink(id: UUID(), url: $0) + #endif + }, + webViewActionHandler: webViewActionHandler, + navBarVisibilityRatioUpdater: navBarVisibilityRatioUpdater, + annotation: $annotation, + annotationSaveTransactionID: $annotationSaveTransactionID, + sendIncreaseFontSignal: $viewModel.sendIncreaseFontSignal, + sendDecreaseFontSignal: $viewModel.sendDecreaseFontSignal + ) } .sheet(item: $safariWebLink) { SafariView(url: $0.url) @@ -92,16 +87,9 @@ public struct WebAppWrapperView: View { guard let messageBody = message.body as? [String: String] else { return } guard let actionID = messageBody["actionID"] else { return } - switch actionID { - case "share": - if let highlightId = messageBody["highlightID"] { - viewModel.performActionSubject.send(.shareHighlight(highlightID: highlightId)) - } - case "annotate": + if actionID == "annotate" { annotation = messageBody["annotation"] ?? "" showHighlightAnnotationModal = true - default: - break } } }