mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
New account selection menu
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import Defaults
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct AccountSelectionView: View {
|
||||
var showHeader = true
|
||||
|
||||
@ObservedObject private var accountsModel = AccountsModel.shared
|
||||
|
||||
@Default(.accounts) private var accounts
|
||||
@Default(.instances) private var instances
|
||||
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
|
||||
|
||||
var body: some View {
|
||||
Section(header: Text(showHeader ? "Current Location" : "")) {
|
||||
Button(accountButtonTitle(account: accountsModel.current)) {
|
||||
if let account = nextAccount {
|
||||
accountsModel.setCurrent(account)
|
||||
}
|
||||
}
|
||||
.disabled(instances.isEmpty && Defaults[.countryOfPublicInstances].isNil)
|
||||
.contextMenu {
|
||||
ForEach(allAccounts) { account in
|
||||
Button(accountButtonTitle(account: account)) {
|
||||
accountsModel.setCurrent(account)
|
||||
}
|
||||
}
|
||||
|
||||
Button("Cancel", role: .cancel) {}
|
||||
}
|
||||
}
|
||||
.id(UUID())
|
||||
}
|
||||
|
||||
var allAccounts: [Account] {
|
||||
let anonymousAccounts = accountPickerDisplaysAnonymousAccounts ? instances.map(\.anonymousAccount) : []
|
||||
return accounts + anonymousAccounts + [accountsModel.publicAccount].compactMap { $0 }
|
||||
}
|
||||
|
||||
private var nextAccount: Account? {
|
||||
allAccounts.next(after: accountsModel.current)
|
||||
}
|
||||
|
||||
func accountButtonTitle(account: Account! = nil) -> String {
|
||||
guard account != nil else {
|
||||
return "Not selected"
|
||||
}
|
||||
|
||||
return account.isPublic ? account.description : "\(account.description) — \(account.instance.shortDescription)"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user