Save last used account instead of having to set default

This commit is contained in:
Arkadiusz Fal
2021-10-19 23:27:04 +02:00
parent 00d706766c
commit 2d075e7b3a
23 changed files with 169 additions and 273 deletions

View File

@@ -4,24 +4,29 @@ import SwiftUI
struct AccountsMenuView: View {
@EnvironmentObject<AccountsModel> private var model
@Default(.accounts) private var accounts
@Default(.instances) private var instances
var body: some View {
Menu {
ForEach(model.all, id: \.id) { account in
ForEach(allAccounts, id: \.id) { account in
Button(accountButtonTitle(account: account)) {
model.setAccount(account)
model.setCurrent(account)
}
}
} label: {
Label(model.account?.name ?? "Select Account", systemImage: "person.crop.circle")
Label(model.current?.name ?? "Select Account", systemImage: "person.crop.circle")
.labelStyle(.titleAndIcon)
}
.disabled(instances.isEmpty)
.transaction { t in t.animation = .none }
}
func accountButtonTitle(account: Instance.Account) -> String {
private var allAccounts: [Instance.Account] {
accounts + instances.map(\.anonymousAccount)
}
private func accountButtonTitle(account: Instance.Account) -> String {
instances.count > 1 ? "\(account.description)\(account.instance.description)" : account.description
}
}