2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AccountsMenuView: View {
|
2021-10-16 22:48:58 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var model
|
2021-09-26 20:39:27 +00:00
|
|
|
@EnvironmentObject<InstancesModel> private var instancesModel
|
2021-09-25 08:18:22 +00:00
|
|
|
|
|
|
|
@Default(.instances) private var instances
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Menu {
|
2021-10-16 22:48:58 +00:00
|
|
|
ForEach(model.all, id: \.id) { account in
|
|
|
|
Button(accountButtonTitle(account: account)) {
|
|
|
|
model.setAccount(account)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} label: {
|
2021-10-16 22:48:58 +00:00
|
|
|
Label(model.account?.name ?? "Select Account", systemImage: "person.crop.circle")
|
2021-09-25 08:18:22 +00:00
|
|
|
.labelStyle(.titleAndIcon)
|
|
|
|
}
|
|
|
|
.disabled(instances.isEmpty)
|
|
|
|
.transaction { t in t.animation = .none }
|
|
|
|
}
|
|
|
|
|
2021-10-16 22:48:58 +00:00
|
|
|
func accountButtonTitle(account: Instance.Account) -> String {
|
|
|
|
instances.count > 1 ? "\(account.description) — \(account.instance.description)" : account.description
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|