From be4fea153a6693e5782ef9f2782ae529d5b1a540 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 7 Apr 2023 11:44:45 +0800 Subject: [PATCH] Filter out highlights that are scheduled for deletion --- .../App/Views/Highlights/NotebookViewModel.swift | 11 ++++++++++- .../Sources/Services/DataService/ContentLoading.swift | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Highlights/NotebookViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Highlights/NotebookViewModel.swift index 406b1c909..a20b4eb9f 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Highlights/NotebookViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Highlights/NotebookViewModel.swift @@ -14,7 +14,14 @@ struct HighlightListItemParams: Identifiable { let createdBy: InternalUserProfile? } +struct NoteItemParams: Identifiable { + let id = UUID() + let highlightID: String + let annotation: String +} + @MainActor final class NotebookViewModel: ObservableObject { + @Published var noteItem: NoteItemParams? @Published var highlightItems = [HighlightListItemParams]() func load(itemObjectID: NSManagedObjectID, dataService: DataService) { @@ -72,7 +79,9 @@ struct HighlightListItemParams: Identifiable { } private func loadHighlights(item: LinkedItem) { - let unsortedHighlights = item.highlights.asArray(of: Highlight.self).filter { $0.type == "HIGHLIGHT" } + let notes = item.highlights.asArray(of: Highlight.self).filter { $0.type == "NOTE" } + let unsortedHighlights = item.highlights.asArray(of: Highlight.self) + .filter { $0.type == "HIGHLIGHT" && $0.serverSyncStatus != ServerSyncStatus.needsDeletion.rawValue } let highlights = unsortedHighlights.sorted { left, right in if left.positionPercent > 0, right.positionPercent > 0 { diff --git a/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift b/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift index b1b620be8..f32e5005c 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift @@ -87,7 +87,9 @@ extension DataService { return ArticleContent( title: linkedItem.unwrappedTitle, htmlContent: htmlContent, - highlightsJSONString: highlights.map { InternalHighlight.make(from: $0) }.asJSONString, + highlightsJSONString: highlights + .filter { $0.serverSyncStatus != ServerSyncStatus.needsDeletion.rawValue } + .map { InternalHighlight.make(from: $0) }.asJSONString, contentStatus: .succeeded, objectID: linkedItem.objectID )