Mercurial > public > lazybear
changeset 199:e15980164e2d
Update settings
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 26 Feb 2021 20:00:20 +0000 |
parents | 62828b2352f4 |
children | 6055ff3d400c |
files | LazyBear/UI/Settings.swift |
diffstat | 1 files changed, 14 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear/UI/Settings.swift Fri Feb 26 20:00:00 2021 +0000 +++ b/LazyBear/UI/Settings.swift Fri Feb 26 20:00:20 2021 +0000 @@ -9,37 +9,28 @@ import CoreData struct Settings: View { - @Environment(\.managedObjectContext) private var moc - @State var theme = "" - + @FetchRequest(entity: UserSettings.entity(), + sortDescriptors: [NSSortDescriptor(keyPath: \UserSettings.changedAt, ascending: false)]) + var userSettings: FetchedResults<UserSettings> + var body: some View { NavigationView { Form { - Picker("Themes", selection: $theme) { - ForEach(themes, id: \.name) { theme in - Text(theme.name) - .tag(theme.name) - } + let theme = userSettings.first?.theme ?? "Default" + let language = userSettings.first?.newsLanguage ?? "en" + ThemePicker(theme: theme) + NewsLanguagePicker(language: language) + + Section { + SettingRow(image: "at", text: "About", colour: .systemBlue) + SettingRow(image: "bag.fill", text: "Tip jar", colour: .systemGreen) + SettingRow(image: "suit.heart.fill", text: "Rate Lazybear", colour: .systemRed) + } - .onChange(of: theme, perform: { theme in - save(change: theme) - }) } .navigationTitle("Settings 👨🏻🔧") } } - - private func save(change: Any) { - let userSettings = UserSettings(context: moc) - userSettings.theme = change as? String - userSettings.changedAt = Date() - do { - try moc.save() - print("Core Data saved") - } catch { - print(error.localizedDescription) - } - } }