diff options
Diffstat (limited to 'Sora/Data')
| -rw-r--r-- | Sora/Data/Booru/BooruSearchQuery.swift | 8 | ||||
| -rw-r--r-- | Sora/Data/Settings/Settings.swift | 29 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Sora/Data/Booru/BooruSearchQuery.swift b/Sora/Data/Booru/BooruSearchQuery.swift new file mode 100644 index 0000000..a87e192 --- /dev/null +++ b/Sora/Data/Booru/BooruSearchQuery.swift @@ -0,0 +1,8 @@ +import Foundation + +struct BooruSearchQuery: Codable, Equatable, Identifiable { + var id = UUID() + let provider: BooruProvider + let tags: [String] + let searchedAt: Date +} diff --git a/Sora/Data/Settings/Settings.swift b/Sora/Data/Settings/Settings.swift index fc0a0cc..e708d5b 100644 --- a/Sora/Data/Settings/Settings.swift +++ b/Sora/Data/Settings/Settings.swift @@ -37,6 +37,9 @@ class Settings: ObservableObject { @AppStorage("displayDetailsInformationBar") var displayDetailsInformationBar = true + @AppStorage("searchHistory") + private var searchHistoryData = Data() + #if os(macOS) @AppStorage("saveTagsToFile") var saveTagsToFile = true @@ -68,6 +71,32 @@ class Settings: ObservableObject { set { if let data = Self.encodeRatings(newValue) { blurRatingsData = data } } } + var searchHistory: [BooruSearchQuery] { + get { + if let history = try? JSONDecoder().decode([BooruSearchQuery].self, from: searchHistoryData) { + return history + } + + return [] + } + + set { + if let data = try? JSONEncoder().encode(newValue) { + searchHistoryData = data + } + } + } + + func appendToSearchHistory(_ query: BooruSearchQuery) { + self.searchHistory.append(query) + } + + func removeFromSearchHistory(_ query: BooruSearchQuery) { + if let index = self.searchHistory.firstIndex(of: query) { + self.searchHistory.remove(at: index) + } + } + private static func defaultRatingsData() -> Data { do { return try JSONEncoder().encode(BooruRating.allCases) |