1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 14:20:32 +05:30
yattee/Shared/Navigation/AccountsMenuView.swift

28 lines
853 B
Swift
Raw Normal View History

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