update item reading progress when signal is ent from web app view

This commit is contained in:
Satindar Dhillon 2022-03-08 20:53:26 -08:00
parent ddb13770d3
commit 525cb9b8b9
2 changed files with 6 additions and 6 deletions

View file

@ -87,12 +87,12 @@ final class LinkItemDetailViewModel: ObservableObject {
rawAuthCookie: rawAuthCookie
)
newWebAppWrapperViewModel.performActionSubject.sink { action in
newWebAppWrapperViewModel.performActionSubject.sink { [weak self] action in
switch action {
case let .shareHighlight(highlightID):
print("show share modal for highlight with id: \(highlightID)")
case let .updateReadingProgess(progress: progress):
print("new reading progress: \(progress)")
self?.item.readingProgress = Double(progress)
}
}
.store(in: &newWebAppWrapperViewModel.subscriptions)

View file

@ -6,7 +6,7 @@ import WebKit
public final class WebAppWrapperViewModel: ObservableObject {
public enum Action {
case shareHighlight(highlightID: String)
case updateReadingProgess(progress: Double)
case updateReadingProgess(progress: Int)
}
public var subscriptions = Set<AnyCancellable>()
@ -87,11 +87,11 @@ public struct WebAppWrapperView: View {
if message.name == WebViewAction.highlightAction.rawValue {
handleHighlightAction(message: message)
}
if message.name == WebViewAction.readingProgressUpdate.rawValue {
guard let messageBody = message.body as? [String: String] else { return }
guard let messageBody = message.body as? [String: Double] else { return }
guard let progress = messageBody["progress"] else { return }
print(progress)
viewModel.performActionSubject.send(.updateReadingProgess(progress: Int(progress)))
}
}