Fixes and better log out
This commit is contained in:
parent
9f9307b053
commit
604bdb68e6
|
@ -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 {
|
||||||
|
if loggedAccounts.count <= 1 {
|
||||||
AppAccount.clear()
|
AppAccount.clear()
|
||||||
navigator.path = []
|
navigator.path = []
|
||||||
uniNav.selectedTab = .timeline
|
uniNav.selectedTab = .timeline
|
||||||
uniNav.presentedCover = .welcome
|
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,11 +219,13 @@ extension SettingsView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
|
if !currentAccount {
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
modelContext.delete(self.logged)
|
modelContext.delete(self.logged)
|
||||||
} label: {
|
} label: {
|
||||||
Label("settings.account-switcher.remove", systemImage: "trash")
|
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)")
|
||||||
|
|
Loading…
Reference in New Issue