summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-16 10:02:44 -0700
committerFuwn <[email protected]>2025-06-16 10:02:44 -0700
commit375d5b504634915bb17c932ee49aee99036275d0 (patch)
treeb6745fc4134e639895c13160794982e9f0d4694a
parentfeat: Development commit (diff)
downloadsora-testing-375d5b504634915bb17c932ee49aee99036275d0.tar.xz
sora-testing-375d5b504634915bb17c932ee49aee99036275d0.zip
feat: Development commit
-rw-r--r--Localizable.xcstrings3
-rw-r--r--Sora/Data/Booru/BooruManager.swift3
-rw-r--r--Sora/Data/Settings/SettingsManager.swift26
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift8
4 files changed, 38 insertions, 2 deletions
diff --git a/Localizable.xcstrings b/Localizable.xcstrings
index c3f38df..96503f4 100644
--- a/Localizable.xcstrings
+++ b/Localizable.xcstrings
@@ -265,6 +265,9 @@
}
}
},
+ "Provider Error" : {
+
+ },
"Rabbit SVG created by Kim Sun Young" : {
},
diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift
index ce61644..f0cad76 100644
--- a/Sora/Data/Booru/BooruManager.swift
+++ b/Sora/Data/Booru/BooruManager.swift
@@ -19,6 +19,7 @@ class BooruManager: ObservableObject {
@Published var historyIndex: Int = -1
@Published var searchHistory: [BooruSearchQuery] = []
@Published var isNavigatingHistory = false
+ @Published var error: Error?
// MARK: - Private Properties
private var currentTask: Task<Void, Never>?
@@ -98,6 +99,8 @@ class BooruManager: ObservableObject {
pageCache.setObject(cacheEntry, forKey: cacheKey)
updatePosts(newPosts, replace: replace)
} catch {
+ self.error = error
+
debugPrint("BooruManager.fetchPosts: \(error)")
}
diff --git a/Sora/Data/Settings/SettingsManager.swift b/Sora/Data/Settings/SettingsManager.swift
index c824cff..39dbfee 100644
--- a/Sora/Data/Settings/SettingsManager.swift
+++ b/Sora/Data/Settings/SettingsManager.swift
@@ -201,12 +201,34 @@ class SettingsManager: ObservableObject { // swiftlint:disable:this type_body_l
}
}
+ private func mergedCredentialValues<Value>(
+ extract: (BooruProviderCredentials) -> Value,
+ isDefault: (Value) -> Bool
+ ) -> [BooruProvider: Value] {
+ providerCredentials.reduce(into: [BooruProvider: Value]()) { dictionary, credentials in
+ let key = credentials.provider
+ let value = extract(credentials)
+
+ if dictionary[key] == nil {
+ dictionary[key] = value
+ } else if isDefault(dictionary[key]!) && !isDefault(value) {
+ dictionary[key] = value
+ }
+ }
+ }
+
var providerAPIKeys: [BooruProvider: String] {
- Dictionary(uniqueKeysWithValues: providerCredentials.map { ($0.provider, $0.apiKey) })
+ mergedCredentialValues(
+ extract: { $0.apiKey },
+ isDefault: { $0.isEmpty }
+ )
}
var providerUserIDs: [BooruProvider: Int] {
- Dictionary(uniqueKeysWithValues: providerCredentials.map { ($0.provider, $0.userID) })
+ mergedCredentialValues(
+ extract: { $0.userID },
+ isDefault: { $0 == 0 }
+ )
}
// MARK: - Initialisation
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 4e283aa..9dce682 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -30,6 +30,14 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
ScrollView {
Group {
+ if let error = manager.error {
+ ContentUnavailableView(
+ "Provider Error",
+ systemImage: "exclamationmark.triangle.fill",
+ description: Text(error.localizedDescription)
+ )
+ }
+
if filteredPosts.isEmpty, isActive, manager.isLoading {
let gridItems = Array(
repeating: GridItem(.flexible()),