mirror of
https://github.com/yattee/yattee.git
synced 2025-12-27 15:10:13 +00:00
Settings UI and code improvements
This commit is contained in:
54
macOS/Settings/AccountSettingsView.swift
Normal file
54
macOS/Settings/AccountSettingsView.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
import Defaults
|
||||
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 {
|
||||
HStack(spacing: 2) {
|
||||
Text(account.description)
|
||||
if instances.defaultAccount == account {
|
||||
Text("— default")
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
if instances.defaultAccount != account {
|
||||
Button("Make default", action: makeDefault)
|
||||
} else {
|
||||
Button("Reset default", action: resetDefault)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
.opacity(account == selectedAccount ? 1 : 0)
|
||||
}
|
||||
}
|
||||
|
||||
private func makeDefault() {
|
||||
instances.setDefaultAccount(account)
|
||||
}
|
||||
|
||||
private func resetDefault() {
|
||||
instances.resetDefaultAccount()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user