Fixes and better log out

This commit is contained in:
Lumaa 2024-03-08 14:29:11 +01:00
parent 9f9307b053
commit 604bdb68e6
1 changed files with 32 additions and 10 deletions

View File

@ -4,7 +4,7 @@ import SwiftUI
import SwiftData import SwiftData
import WatchConnectivity import WatchConnectivity
//TODO: Bring back "Privacy" with mutelist, blocklist and default visibility //TODO: "Privacy" with mutelist, blocklist
struct SettingsView: View { struct SettingsView: View {
@Environment(UniversalNavigator.self) private var uniNav: UniversalNavigator @Environment(UniversalNavigator.self) private var uniNav: UniversalNavigator
@ -99,10 +99,30 @@ struct SettingsView: View {
.listRowThreaded() .listRowThreaded()
Button { Button {
AppAccount.clear() if loggedAccounts.count <= 1 {
navigator.path = [] AppAccount.clear()
uniNav.selectedTab = .timeline navigator.path = []
uniNav.presentedCover = .welcome uniNav.selectedTab = .timeline
uniNav.presentedCover = .welcome
} else {
Task {
if let app = loggedAccounts[0].app {
let c: Client = Client(server: app.server, oauthToken: app.oauthToken)
let am: AccountManager = .init(client: c)
let fetched: Account? = await am.fetchAccount()
if fetched == nil {
am.clear()
} else {
AccountManager.shared.setAccount(fetched!)
AccountManager.shared.setClient(c)
navigator.path = []
uniNav.selectedTab = .timeline
}
}
}
}
} label: { } label: {
Text("logout") Text("logout")
.foregroundStyle(.red) .foregroundStyle(.red)
@ -199,10 +219,12 @@ extension SettingsView {
} }
} }
.contextMenu { .contextMenu {
Button(role: .destructive) { if !currentAccount {
modelContext.delete(self.logged) Button(role: .destructive) {
} label: { modelContext.delete(self.logged)
Label("settings.account-switcher.remove", systemImage: "trash") } label: {
Label("settings.account-switcher.remove", systemImage: "trash")
}
} }
Divider() Divider()
@ -228,7 +250,7 @@ extension SettingsView {
} else { } else {
Circle() Circle()
.fill(error ? Color.red.opacity(0.45) : Color.gray.opacity(0.45)) .fill(error ? Color.red.opacity(0.45) : Color.gray.opacity(0.45))
.frame(width: 54, height: 54) .frame(width: 36, height: 36)
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(Account.placeholder().displayName ?? "@\(Account.placeholder().acct)") Text(Account.placeholder().displayName ?? "@\(Account.placeholder().acct)")