Tusker/Tusker/Screens/Preferences/PreferencesView.swift

66 lines
2.5 KiB
Swift
Raw Normal View History

2019-06-14 00:53:17 +00:00
// PreferencesView.swift
// Tusker
//
// Created by Shadowfacts on 6/13/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import SwiftUI
struct PreferencesView : View {
var currentAccount: LocalData.UserAccountInfo
2019-09-16 17:12:23 +00:00
@State private var showingLogoutConfirmation = false
2019-06-14 00:53:17 +00:00
var body: some View {
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
// NavigationView {
List {
2019-09-16 17:12:23 +00:00
Section {
Button(action: {
self.showingLogoutConfirmation = true
}) {
Text("Logout")
}.alert(isPresented: $showingLogoutConfirmation) {
Alert(title: Text("Are you sure you want to logout?"), message: nil, primaryButton: .destructive(Text("Logout"), action: self.logoutPressed), secondaryButton: .cancel())
}
2019-06-14 00:53:17 +00:00
}
2019-09-16 17:12:23 +00:00
Section {
NavigationLink(destination: AppearancePrefsView()) {
Text("Appearance")
}
NavigationLink(destination: BehaviorPrefsView()) {
Text("Behavior")
}
NavigationLink(destination: WellnessPrefsView()) {
Text("Digital Wellness")
}
NavigationLink(destination: AdvancedPrefsView()) {
Text("Advanced")
}
2019-06-14 00:53:17 +00:00
}
}
2019-08-06 03:08:00 +00:00
.listStyle(GroupedListStyle())
2019-06-14 00:53:17 +00:00
.navigationBarTitle(Text("Preferences"), displayMode: .inline)
.onDisappear {
// todo: this onDisappear callback is not called in beta 4, check again in beta 5
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
}
2019-06-14 00:53:17 +00:00
// }
}
2019-09-16 17:12:23 +00:00
func logoutPressed() {
LocalData.shared.removeAccount(currentAccount)
2019-09-16 17:12:23 +00:00
NotificationCenter.default.post(name: .userLoggedOut, object: nil)
}
2019-06-14 00:53:17 +00:00
}
#if DEBUG
struct PreferencesView_Previews : PreviewProvider {
static var previews: some View {
let account = LocalData.UserAccountInfo(instanceURL: URL(string: "https://mastodon.social")!, clientID: "clientID", clientSecret: "clientSecret", username: "example", accessToken: "accessToken")
return PreferencesView(currentAccount: account)
2019-06-14 00:53:17 +00:00
}
}
#endif