From f7f21300f3b7cf7d96f9b67db64e35c1024886aa Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Wed, 9 Mar 2022 07:42:58 -0800 Subject: [PATCH] update reading progress on the item in home view model --- .../Sources/App/Views/Home/HomeFeedViewModel.swift | 7 +++++++ .../OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index 1d7c11fed..011c1dba6 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -158,4 +158,11 @@ final class HomeFeedViewModel: ObservableObject { ) .store(in: &subscriptions) } + + func updateProgress(itemID: String, progress: Double) { + guard let item = items.first(where: { $0.id == itemID }) else { return } + if let index = items.firstIndex(of: item) { + items[index].readingProgress = progress + } + } } diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 78a3a4199..36b19523f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -92,7 +92,7 @@ final class LinkItemDetailViewModel: ObservableObject { case let .shareHighlight(highlightID): print("show share modal for highlight with id: \(highlightID)") case let .updateReadingProgess(progress: progress): - self?.item.readingProgress = Double(progress) + self?.homeFeedViewModel.updateProgress(itemID: self?.item.id ?? "", progress: Double(progress)) } } .store(in: &newWebAppWrapperViewModel.subscriptions)