From 43dbcfe27c36bab6ed8337b195aa21c5f945b220 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 21 Apr 2022 10:07:46 -0700 Subject: [PATCH] create NSSet extension --- .../Sources/App/PDFSupport/PDFViewerViewModel.swift | 8 ++------ .../Sources/App/Views/Labels/LabelsViewModel.swift | 12 ++++++++++-- .../Sources/Services/DataService/DataService.swift | 10 ---------- .../DataService/Mutations/MergeHighlight.swift | 2 +- .../Mutations/UpdateArticleLabelsPublisher.swift | 5 ++++- .../DataService/Queries/LibraryItemsQuery.swift | 1 + apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift | 10 ++++++++++ 7 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift index 745e78528..7ab9f9a4d 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewerViewModel.swift @@ -74,9 +74,7 @@ public final class PDFViewerViewModel: ObservableObject { .sink { [weak self] completion in guard case let .failure(error) = completion else { return } self?.errorMessage = error.localizedDescription - } receiveValue: { value in - print("highlight value", value) - } + } receiveValue: { _ in } .store(in: &subscriptions) } @@ -100,9 +98,7 @@ public final class PDFViewerViewModel: ObservableObject { .sink { [weak self] completion in guard case let .failure(error) = completion else { return } self?.errorMessage = error.localizedDescription - } receiveValue: { value in - print("highlight value", value) - } + } receiveValue: { _ in } .store(in: &subscriptions) } diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift index 729f72f13..fbdf01fdf 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift @@ -19,7 +19,11 @@ final class LabelsViewModel: ObservableObject { /// - dataService: `DataService` reference /// - item: Optional `FeedItem` for applying labels to a single item /// - initiallySelectedLabels: Optional `[FeedItemLabel]` for filtering a list of items - func loadLabels(dataService: DataService, item: FeedItemDep? = nil, initiallySelectedLabels: [FeedItemLabelDep]? = nil) { + func loadLabels( + dataService: DataService, + item: FeedItemDep? = nil, + initiallySelectedLabels: [FeedItemLabelDep]? = nil + ) { guard !hasLoadedInitialLabels else { return } isLoading = true @@ -82,7 +86,11 @@ final class LabelsViewModel: ObservableObject { .store(in: &subscriptions) } - func saveItemLabelChanges(itemID: String, dataService: DataService, onComplete: @escaping ([FeedItemLabelDep]) -> Void) { + func saveItemLabelChanges( + itemID: String, + dataService: DataService, + onComplete: @escaping ([FeedItemLabelDep]) -> Void + ) { isLoading = true dataService.updateArticleLabelsPublisher(itemID: itemID, labelIDs: selectedLabels.map(\.id)).sink( receiveCompletion: { [weak self] _ in diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index 01aa6bf29..25391e216 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -110,13 +110,3 @@ public extension DataService { func invalidateCachedPage(slug _: String?) {} } - -// TODO: move to util file -extension Optional where Wrapped == NSSet { - func asArray(of _: T.Type) -> [T] { - if let set = self as? Set { - return Array(set) - } - return [T]() - } -} diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/MergeHighlight.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/MergeHighlight.swift index 4f8b8d4bf..eac9bedc8 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/MergeHighlight.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/MergeHighlight.swift @@ -4,7 +4,7 @@ import Models import SwiftGraphQL public extension DataService { - // swiftlint:disable:next function_parameter_count + // swiftlint:disable:next function_parameter_count function_body_length func mergeHighlightPublisher( shortId: String, highlightID: String, diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleLabelsPublisher.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleLabelsPublisher.swift index df552adaa..11d9f4098 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleLabelsPublisher.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateArticleLabelsPublisher.swift @@ -4,7 +4,10 @@ import Models import SwiftGraphQL public extension DataService { - func updateArticleLabelsPublisher(itemID: String, labelIDs: [String]) -> AnyPublisher<[FeedItemLabelDep], BasicError> { + func updateArticleLabelsPublisher( + itemID: String, + labelIDs: [String] + ) -> AnyPublisher<[FeedItemLabelDep], BasicError> { enum MutationResult { case saved(feedItem: [FeedItemLabelDep]) case error(errorCode: Enums.SetLabelsErrorCode) diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift index f00dc9466..452246959 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LibraryItemsQuery.swift @@ -5,6 +5,7 @@ import Models import SwiftGraphQL public extension DataService { + // swiftlint:disable:next function_body_length func libraryItemsPublisher( limit: Int, sortDescending: Bool, diff --git a/apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift b/apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift new file mode 100644 index 000000000..4ad91f704 --- /dev/null +++ b/apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift @@ -0,0 +1,10 @@ +import Foundation + +public extension Optional where Wrapped == NSSet { + func asArray(of _: T.Type) -> [T] { + if let set = self as? Set { + return Array(set) + } + return [T]() + } +}