attempt to mitigate line length warnings

This commit is contained in:
Sixten Otto
2023-02-20 12:09:39 -07:00
parent 6fd8729291
commit edb9d5cfca
12 changed files with 57 additions and 23 deletions

View File

@ -44,7 +44,12 @@ import Views
let fetchRequest: NSFetchRequest<Models.RecentSearchItem> = 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()

View File

@ -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)
}
)

View File

@ -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

View File

@ -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) ?? "[]"
}

View File

@ -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

View File

@ -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<MutationResult, Unions.OptInFeatureResult> {
try $0.on(
optInFeatureError: .init { .error(errorCode: try $0.errorCodes().first ?? .badRequest) },

View File

@ -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
)
}

View File

@ -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
)
}

View File

@ -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(

View File

@ -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)
}

View File

@ -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)

View File

@ -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)