yattee/macOS/Settings/AccountSettingsView.swift

55 lines
1.6 KiB
Swift
Raw Normal View History

2021-09-26 22:03:33 +00:00
import Defaults
2021-09-25 08:18:22 +00:00
import SwiftUI
struct AccountSettingsView: View {
let account: Instance.Account
@Binding var selectedAccount: Instance.Account?
@State private var presentingRemovalConfirmationDialog = false
@EnvironmentObject<InstancesModel> private var instances
var body: some View {
HStack {
2021-09-26 22:03:33 +00:00
HStack(spacing: 2) {
Text(account.description)
if instances.defaultAccount == account {
Text("— default")
.foregroundColor(.secondary)
}
}
2021-09-25 08:18:22 +00:00
Spacer()
HStack {
2021-09-26 22:03:33 +00:00
if instances.defaultAccount != account {
Button("Make default", action: makeDefault)
} else {
Button("Reset default", action: resetDefault)
}
2021-09-25 08:18:22 +00:00
Button("Remove", role: .destructive) {
presentingRemovalConfirmationDialog = true
}
.confirmationDialog(
"Are you sure you want to remove \(account.description) account?",
isPresented: $presentingRemovalConfirmationDialog
) {
Button("Remove", role: .destructive) {
instances.removeAccount(account)
2021-09-25 08:18:22 +00:00
}
}
2021-09-29 10:14:43 +00:00
.foregroundColor(.red)
2021-09-25 08:18:22 +00:00
}
.opacity(account == selectedAccount ? 1 : 0)
}
}
2021-09-26 22:03:33 +00:00
private func makeDefault() {
instances.setDefaultAccount(account)
}
private func resetDefault() {
instances.resetDefaultAccount()
}
2021-09-25 08:18:22 +00:00
}