Skip to content

Commit

Permalink
Merge pull request #39 from Athlon007/preferences-tochups
Browse files Browse the repository at this point in the history
Preferences tochups
  • Loading branch information
Athlon007 authored Jul 21, 2023
2 parents d9568d8 + ca897a4 commit d1117a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Leomard/Views/PreferenceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ struct PreferencesView: View {
manuallyCheckedForUpdate = true
})
.disabled(manuallyCheckedForUpdate)
Text("Last updated:")
DateDisplayView(date: UserPreferences.getInstance.lastUpdateCheckDate, showRealTime: true, noBrackets: true, noTapAction: true)
if manuallyCheckedForUpdate {
Image(systemName: "checkmark")
.foregroundColor(.green)
Expand Down
33 changes: 29 additions & 4 deletions Leomard/Views/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct ProfileView: View {

@State var sessionChangeFail: Bool = false

@State var showLogoutAlert: Bool = false

var body: some View {
toolbar
.frame(
Expand Down Expand Up @@ -265,17 +267,40 @@ struct ProfileView: View {
.onChange(of: selectededSession) { change in
performSwitch(change)
}
Button("Logout", action: logout)
Button("Logout", action: { showLogoutAlert = true })
.alert("Logout", isPresented: $showLogoutAlert, actions: {
Button("Logout", role: .destructive) { logout() }
Button("Cancel", role: .cancel) {}
}, message: {
Text("Are you sure you want to logout?")
})
}
}
}

// MARK: -

func logout() {
_ = SessionStorage.getInstance.endSession()
contentView.navigateToFeed()
contentView.logout()
let toDestroy = SessionStorage.getInstance.getCurrentSession()
if SessionStorage.getInstance.getAllSessions().count > 1 {
// Is there more than 1 session stored? Switch to the one that's not used
if SessionStorage.getInstance.getAllSessions()[0] == toDestroy {
_ = SessionStorage.getInstance.setCurrentSession(SessionStorage.getInstance.getAllSessions()[1])
} else {
_ = SessionStorage.getInstance.setCurrentSession(SessionStorage.getInstance.getAllSessions()[0])
}

// Destroy the session
_ = SessionStorage.getInstance.remove(session: toDestroy!)

self.contentView.navigateToFeed()
self.contentView.loadUserData()
} else {
_ = SessionStorage.getInstance.endSession()
_ = SessionStorage.getInstance.remove(session: toDestroy!)
contentView.navigateToFeed()
contentView.logout()
}
}

func loadPersonDetails() {
Expand Down

0 comments on commit d1117a5

Please sign in to comment.