diff --git a/Model/Country.swift b/Model/Country.swift index 3be972fb..890369e0 100644 --- a/Model/Country.swift +++ b/Model/Country.swift @@ -1,6 +1,7 @@ // swiftlint:disable switch_case_on_newline +import Defaults -enum Country: String, CaseIterable, Identifiable, Hashable { +enum Country: String, CaseIterable, Identifiable, Hashable, Defaults.Serializable { var id: String { rawValue } diff --git a/Model/TrendingCategory.swift b/Model/TrendingCategory.swift index be94d6c6..b022b108 100644 --- a/Model/TrendingCategory.swift +++ b/Model/TrendingCategory.swift @@ -1,4 +1,6 @@ -enum TrendingCategory: String, CaseIterable, Identifiable { +import Defaults + +enum TrendingCategory: String, CaseIterable, Identifiable, Defaults.Serializable { case `default`, music, gaming, movies var id: TrendingCategory.RawValue { diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index f81e7fca..fcb797ad 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -9,6 +9,9 @@ extension Defaults.Keys { static let accounts = Key<[Instance.Account]>("accounts", default: []) static let defaultAccountID = Key("defaultAccountID") + static let trendingCategory = Key("trendingCategory", default: .default) + static let trendingCountry = Key("trendingCountry", default: .us) + static let selectedPlaylistID = Key("selectedPlaylistID") static let showingAddToPlaylist = Key("showingAddToPlaylist", default: false) static let videoIDToAddToPlaylist = Key("videoIDToAddToPlaylist") diff --git a/Shared/Trending/TrendingCountry.swift b/Shared/Trending/TrendingCountry.swift index 9c9faf4d..fb92b8f4 100644 --- a/Shared/Trending/TrendingCountry.swift +++ b/Shared/Trending/TrendingCountry.swift @@ -2,7 +2,7 @@ import SwiftUI struct TrendingCountry: View { static let prompt = "Country Name or Code" - @Binding var selectedCountry: Country? + @Binding var selectedCountry: Country @StateObject private var store = Store(Country.allCases) @@ -87,9 +87,7 @@ struct TrendingCountry: View { } func selectCountryAndDismiss(_ country: Country? = nil) { - let selected = country ?? selection - - if selected != nil { + if let selected = country ?? selection { selectedCountry = selected } diff --git a/Shared/Trending/TrendingView.swift b/Shared/Trending/TrendingView.swift index bda63215..cb63000a 100644 --- a/Shared/Trending/TrendingView.swift +++ b/Shared/Trending/TrendingView.swift @@ -1,11 +1,13 @@ +import Defaults import Siesta import SwiftUI struct TrendingView: View { @StateObject private var store = Store<[Video]>() - @State private var category: TrendingCategory = .default - @State private var country: Country! = .pl + @Default(.trendingCategory) private var category + @Default(.trendingCountry) private var country + @State private var presentingCountrySelection = false @EnvironmentObject private var api