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: 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() showOnboardingUI()
} }
NotificationCenter.default.addObserver(self, selector: #selector(onUserLoggedOut), name: .userLoggedOut, object: nil)
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
@ -93,6 +95,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
onboarding.onboardingDelegate = self onboarding.onboardingDelegate = self
window!.rootViewController = onboarding window!.rootViewController = onboarding
} }
@objc func onUserLoggedOut() {
showOnboardingUI()
}
} }

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 import SwiftUI
struct PreferencesView : View { struct PreferencesView : View {
@State private var showingLogoutConfirmation = false
var body: some View { var body: some View {
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button // workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
// NavigationView { // NavigationView {
List { List {
NavigationLink(destination: AppearancePrefsView()) { Section {
Text("Appearance") 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") Section {
} NavigationLink(destination: AppearancePrefsView()) {
NavigationLink(destination: WellnessPrefsView()) { Text("Appearance")
Text("Digital Wellness") }
} NavigationLink(destination: BehaviorPrefsView()) {
NavigationLink(destination: AdvancedPrefsView()) { Text("Behavior")
Text("Advanced") }
NavigationLink(destination: WellnessPrefsView()) {
Text("Digital Wellness")
}
NavigationLink(destination: AdvancedPrefsView()) {
Text("Advanced")
}
} }
} }
.listStyle(GroupedListStyle()) .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 #if DEBUG