2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
2022-12-12 00:18:29 +00:00
|
|
|
struct AccountViewButton: View {
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var model = AccountsModel.shared
|
2022-12-11 22:15:56 +00:00
|
|
|
private var navigation = NavigationModel.shared
|
2021-09-25 08:18:22 +00:00
|
|
|
|
|
|
|
@Default(.instances) private var instances
|
2022-01-02 19:34:50 +00:00
|
|
|
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2022-07-01 21:28:32 +00:00
|
|
|
@ViewBuilder var body: some View {
|
|
|
|
if !instances.isEmpty {
|
2022-12-11 22:15:56 +00:00
|
|
|
Button {
|
|
|
|
navigation.presentingAccounts = true
|
2022-07-01 21:28:32 +00:00
|
|
|
} label: {
|
2022-12-15 23:13:36 +00:00
|
|
|
HStack(spacing: 6) {
|
2022-07-01 21:28:32 +00:00
|
|
|
if !accountPickerDisplaysUsername || !(model.current?.isPublic ?? true) {
|
2023-07-01 16:38:11 +00:00
|
|
|
if let name = model.current?.app?.rawValue.capitalized {
|
|
|
|
Image(name)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: accountImageSize, height: accountImageSize)
|
2022-12-12 00:18:29 +00:00
|
|
|
} else {
|
|
|
|
Image(systemName: "globe")
|
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if accountPickerDisplaysUsername {
|
|
|
|
label
|
|
|
|
.labelStyle(.titleOnly)
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
.transaction { t in t.animation = .none }
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 10:48:04 +00:00
|
|
|
private var accountImageSize: Double {
|
|
|
|
#if os(macOS)
|
|
|
|
20
|
|
|
|
#else
|
|
|
|
30
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
private var label: some View {
|
2022-07-01 21:28:32 +00:00
|
|
|
Label(model.current?.description ?? "Select Account", systemImage: "globe")
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|