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()
}
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,10 +8,23 @@
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 {
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())
}
}
Section {
NavigationLink(destination: AppearancePrefsView()) {
Text("Appearance")
}
@ -25,6 +38,7 @@ struct PreferencesView : View {
Text("Advanced")
}
}
}
.listStyle(GroupedListStyle())
.navigationBarTitle(Text("Preferences"), displayMode: .inline)
.onDisappear {
@ -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