diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/LibrarySearchViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/LibrarySearchViewModel.swift index f092b1979..eefa5b307 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/LibrarySearchViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/LibrarySearchViewModel.swift @@ -44,7 +44,12 @@ import Views let fetchRequest: NSFetchRequest = RecentSearchItem.fetchRequest() fetchRequest.predicate = NSPredicate(format: "term == %@", searchTerm) - let item = ((try? dataService.viewContext.fetch(fetchRequest))?.first) ?? RecentSearchItem(context: dataService.viewContext) + let item: RecentSearchItem + if let fetchedItem = (try? dataService.viewContext.fetch(fetchRequest))?.first { + item = fetchedItem + } else { + item = RecentSearchItem(context: dataService.viewContext) + } item.term = searchTerm item.savedAt = Date() diff --git a/apple/OmnivoreKit/Sources/App/Views/SelfHostSettingsView.swift b/apple/OmnivoreKit/Sources/App/Views/SelfHostSettingsView.swift index 567663b5c..e35dc0dd4 100644 --- a/apple/OmnivoreKit/Sources/App/Views/SelfHostSettingsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/SelfHostSettingsView.swift @@ -69,7 +69,9 @@ struct SelfHostSettingsView: View { Alert( title: Text("Changing your environment settings will close the app."), dismissButton: .cancel(Text(LocalText.genericOk)) { - AppEnvironment.setCustom(serverBaseURL: apiServerAddress, webAppBaseURL: webServerAddress, ttsBaseURL: ttsServerAddress) + AppEnvironment.setCustom(serverBaseURL: apiServerAddress, + webAppBaseURL: webServerAddress, + ttsBaseURL: ttsServerAddress) dataService.switchAppEnvironment(appEnvironment: AppEnvironment.custom) } ) diff --git a/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift b/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift index d3f53eb49..d29e3d8a8 100644 --- a/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift +++ b/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift @@ -58,7 +58,10 @@ public extension AppEnvironment { case .test, .local: return URL(string: "http://localhost:4000")! case .custom: - guard let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.serverBaseURL.rawValue), let url = URL(string: str) else { + guard + let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.serverBaseURL.rawValue), + let url = URL(string: str) + else { fatalError("custom serverBaseURL not set") } return url @@ -74,7 +77,10 @@ public extension AppEnvironment { case .test, .local: return URL(string: "http://localhost:3000")! case .custom: - guard let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.webAppBaseURL.rawValue), let url = URL(string: str) else { + guard + let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.webAppBaseURL.rawValue), + let url = URL(string: str) + else { fatalError("custom webAppBaseURL not set") } return url @@ -90,7 +96,10 @@ public extension AppEnvironment { case .test, .local: return URL(string: "http://localhost:4000")! case .custom: - guard let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.ttsBaseURL.rawValue), let url = URL(string: str) else { + guard + let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.ttsBaseURL.rawValue), + let url = URL(string: str) + else { fatalError("custom ttsBaseURL not set") } return url diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift index 937cc1631..8f998469b 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift @@ -156,7 +156,9 @@ public extension LinkedItem { "recommendedAt": recommendedAt == nil ? nil : NSString(string: recommendedAt!) ] } - guard let JSON = (try? JSONSerialization.data(withJSONObject: recommendations, options: .prettyPrinted)) else { return "[]" } + guard let JSON = try? JSONSerialization.data(withJSONObject: recommendations, options: .prettyPrinted) else { + return "[]" + } return String(data: JSON, encoding: .utf8) ?? "[]" } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift index 56c07cc2c..5ca6c8aab 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/DataService.swift @@ -29,9 +29,9 @@ public final class DataService: ObservableObject { persistentContainer.viewContext } - @AppStorage(UserDefaultKey.lastItemSyncTime.rawValue) public var lastItemSyncTime = DateFormatter.formatterISO8601.string( - from: Date(timeIntervalSinceReferenceDate: 0) - ) + @AppStorage(UserDefaultKey.lastItemSyncTime.rawValue) public var lastItemSyncTime: String = { + DateFormatter.formatterISO8601.string(from: Date(timeIntervalSinceReferenceDate: 0)) + }() public init(appEnvironment: AppEnvironment, networker: Networker) { self.appEnvironment = appEnvironment diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/OptIntoFeature.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/OptIntoFeature.swift index 2202b95db..19a9f6060 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/OptIntoFeature.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/OptIntoFeature.swift @@ -22,7 +22,9 @@ public extension DataService { case error(errorCode: Enums.OptInFeatureErrorCode) } - let featureSelection = Selection.Feature { Feature(name: try $0.name(), token: try $0.token(), granted: try $0.grantedAt() != nil) } + let featureSelection = Selection.Feature { + Feature(name: try $0.name(), token: try $0.token(), granted: try $0.grantedAt() != nil) + } let selection = Selection { try $0.on( optInFeatureError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) }, diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift index dab5dfbeb..041dcca0f 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift @@ -21,7 +21,10 @@ public extension DataService { let mutation = Selection.Mutation { try $0.recommend( - input: .init(groupIds: groupIDs, note: OptionalArgument(note), pageId: pageID, recommendedWithHighlights: OptionalArgument(withHighlights)), + input: .init(groupIds: groupIDs, + note: OptionalArgument(note), + pageId: pageID, + recommendedWithHighlights: OptionalArgument(withHighlights)), selection: selection ) } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateLinkedItemTitle.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateLinkedItemTitle.swift index 70cf059e1..9c2689094 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateLinkedItemTitle.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/UpdateLinkedItemTitle.swift @@ -48,7 +48,10 @@ extension DataService { let mutation = Selection.Mutation { try $0.updatePage( - input: .init(byline: OptionalArgument(author), description: OptionalArgument(description), pageId: itemID, title: OptionalArgument(title)), + input: .init(byline: OptionalArgument(author), + description: OptionalArgument(description), + pageId: itemID, + title: OptionalArgument(title)), selection: selection ) } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift index c560cbcb1..7f897bc04 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift @@ -68,7 +68,8 @@ extension DataService { ) } - let sort = InputObjects.SortParams(by: Enums.SortBy.updatedTime, order: OptionalArgument(descending ? Enums.SortOrder.descending : Enums.SortOrder.ascending)) + let sort = InputObjects.SortParams(by: .updatedTime, + order: OptionalArgument(descending ? .descending : .ascending)) let query = Selection.Query { try $0.updatesSince( diff --git a/apple/OmnivoreKit/Sources/Views/Article/OmnivoreWebView.swift b/apple/OmnivoreKit/Sources/Views/Article/OmnivoreWebView.swift index f840e46a7..cdf83035b 100644 --- a/apple/OmnivoreKit/Sources/Views/Article/OmnivoreWebView.swift +++ b/apple/OmnivoreKit/Sources/Views/Article/OmnivoreWebView.swift @@ -353,13 +353,18 @@ public final class OmnivoreWebView: WKWebView { override public func buildMenu(with builder: UIMenuBuilder) { if #available(iOS 16.0, *) { let annotate = UICommand(title: "Note", action: #selector(annotateSelection)) - let highlight = UICommand(title: LocalText.genericHighlight, action: #selector(highlightSelection)) - let remove = UICommand(title: "Remove", action: #selector(removeSelection)) - let setLabels = UICommand(title: LocalText.labelsGeneric, action: #selector(setLabels)) - let omnivore = UIMenu(title: "", - options: .displayInline, - children: currentMenu == .defaultMenu ? [highlight, annotate] : [annotate, setLabels, remove]) + let items: [UIMenuElement] + if currentMenu == .defaultMenu { + let highlight = UICommand(title: LocalText.genericHighlight, action: #selector(highlightSelection)) + items = [highlight, annotate] + } else { + let remove = UICommand(title: "Remove", action: #selector(removeSelection)) + let setLabels = UICommand(title: LocalText.labelsGeneric, action: #selector(setLabels)) + items = [annotate, setLabels, remove] + } + + let omnivore = UIMenu(title: "", options: .displayInline, children: items) builder.insertSibling(omnivore, beforeMenu: .lookup) } diff --git a/apple/OmnivoreKit/Sources/Views/CommunityModal.swift b/apple/OmnivoreKit/Sources/Views/CommunityModal.swift index fe02d05ec..3a91cfa46 100644 --- a/apple/OmnivoreKit/Sources/Views/CommunityModal.swift +++ b/apple/OmnivoreKit/Sources/Views/CommunityModal.swift @@ -101,8 +101,9 @@ public struct CommunityModal: View { VStack(spacing: 0) { header - Text((try? AttributedString(markdown: message, - options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))) ?? "") + let parsedMessage = try? AttributedString(markdown: message, + options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)) + Text(parsedMessage ?? "") .multilineTextAlignment(.leading) .foregroundColor(Color.appGrayTextContrast) .accentColor(.blue) diff --git a/apple/OmnivoreKit/Sources/Views/FeaturePrimer.swift b/apple/OmnivoreKit/Sources/Views/FeaturePrimer.swift index fe91e170c..2da257873 100644 --- a/apple/OmnivoreKit/Sources/Views/FeaturePrimer.swift +++ b/apple/OmnivoreKit/Sources/Views/FeaturePrimer.swift @@ -33,8 +33,9 @@ public struct FeaturePrimer: View { } ScrollView { - Text((try? AttributedString(markdown: message, - options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))) ?? "") + let parsedMessage = try? AttributedString(markdown: message, + options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)) + Text(parsedMessage ?? "") .foregroundColor(Color.appGrayText) .accentColor(.blue) .padding(.bottom, 16)