Add logout button to preferences

This commit is contained in:
Shadowfacts 2019-09-16 13:12:23 -04:00
parent bc2e3c37a0
commit 65ceb83d2d
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 43 additions and 10 deletions

View File

@ -22,6 +22,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
showOnboardingUI()
}
NotificationCenter.default.addObserver(self, selector: #selector(onUserLoggedOut), name: .userLoggedOut, object: nil)
window!.makeKeyAndVisible()
return true
@ -94,6 +96,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window!.rootViewController = onboarding
}
@objc func onUserLoggedOut() {
showOnboardingUI()
}
}
extension AppDelegate: OnboardingViewControllerDelegate {

View File

@ -68,3 +68,7 @@ class LocalData {
}
}
extension Notification.Name {
static let userLoggedOut = Notification.Name("userLoggedOut")
}

View File

@ -8,21 +8,35 @@
import SwiftUI
struct PreferencesView : View {
@State private var showingLogoutConfirmation = false
var body: some View {
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
// NavigationView {
List {
NavigationLink(destination: AppearancePrefsView()) {
Text("Appearance")
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())
}
}
NavigationLink(destination: BehaviorPrefsView()) {
Text("Behavior")
}
NavigationLink(destination: WellnessPrefsView()) {
Text("Digital Wellness")
}
NavigationLink(destination: AdvancedPrefsView()) {
Text("Advanced")
Section {
NavigationLink(destination: AppearancePrefsView()) {
Text("Appearance")
}
NavigationLink(destination: BehaviorPrefsView()) {
Text("Behavior")
}
NavigationLink(destination: WellnessPrefsView()) {
Text("Digital Wellness")
}
NavigationLink(destination: AdvancedPrefsView()) {
Text("Advanced")
}
}
}
.listStyle(GroupedListStyle())
@ -33,6 +47,15 @@ struct PreferencesView : View {
}
// }
}
func logoutPressed() {
LocalData.shared.onboardingComplete = false
LocalData.shared.instanceURL = nil
LocalData.shared.clientID = nil
LocalData.shared.clientSecret = nil
LocalData.shared.accessToken = nil
NotificationCenter.default.post(name: .userLoggedOut, object: nil)
}
}
#if DEBUG