mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Save last used account instead of having to set default
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
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()
|
||||
}
|
||||
}
|
@@ -9,7 +9,8 @@ struct InstancesSettingsView: View {
|
||||
@State private var presentingInstanceForm = false
|
||||
@State private var savedFormInstanceID: Instance.ID?
|
||||
|
||||
@State private var presentingConfirmationDialog = false
|
||||
@State private var presentingAccountRemovalConfirmation = false
|
||||
@State private var presentingInstanceRemovalConfirmation = false
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<InstancesModel> private var model
|
||||
@@ -41,8 +42,26 @@ struct InstancesSettingsView: View {
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
ForEach(selectedInstanceAccounts) { account in
|
||||
AccountSettingsView(account: account, selectedAccount: $selectedAccount)
|
||||
.tag(account)
|
||||
HStack {
|
||||
Text(account.description)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Remove", role: .destructive) {
|
||||
presentingAccountRemovalConfirmation = true
|
||||
}
|
||||
.foregroundColor(.red)
|
||||
.opacity(account == selectedAccount ? 1 : 0)
|
||||
}
|
||||
.tag(account)
|
||||
}
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Are you sure you want to remove \(selectedAccount?.description ?? "") account?",
|
||||
isPresented: $presentingAccountRemovalConfirmation
|
||||
) {
|
||||
Button("Remove", role: .destructive) {
|
||||
AccountsModel.remove(selectedAccount!)
|
||||
}
|
||||
}
|
||||
.listStyle(.inset(alternatesRowBackgrounds: true))
|
||||
@@ -58,28 +77,27 @@ struct InstancesSettingsView: View {
|
||||
|
||||
if selectedInstance != nil {
|
||||
HStack {
|
||||
if selectedInstance.supportsAccounts {
|
||||
Button("Add Account...") {
|
||||
selectedAccount = nil
|
||||
presentingAccountForm = true
|
||||
}
|
||||
Button("Add Account...") {
|
||||
selectedAccount = nil
|
||||
presentingAccountForm = true
|
||||
}
|
||||
.disabled(!selectedInstance.supportsAccounts)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Remove Instance", role: .destructive) {
|
||||
presentingConfirmationDialog = true
|
||||
presentingInstanceRemovalConfirmation = true
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Are you sure you want to remove \(selectedInstance!.longDescription) instance?",
|
||||
isPresented: $presentingConfirmationDialog
|
||||
isPresented: $presentingInstanceRemovalConfirmation
|
||||
) {
|
||||
Button("Remove Instance", role: .destructive) {
|
||||
if accounts.account?.instance == selectedInstance {
|
||||
accounts.setAccount(nil)
|
||||
if accounts.current?.instance == selectedInstance {
|
||||
accounts.setCurrent(nil)
|
||||
}
|
||||
|
||||
model.remove(selectedInstance!)
|
||||
InstancesModel.remove(selectedInstance!)
|
||||
selectedInstanceID = instances.last?.id
|
||||
}
|
||||
}
|
||||
@@ -91,9 +109,6 @@ struct InstancesSettingsView: View {
|
||||
Button("Add Instance...") {
|
||||
presentingInstanceForm = true
|
||||
}
|
||||
|
||||
DefaultAccountHint()
|
||||
.padding(.top, 10)
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
@@ -116,7 +131,7 @@ struct InstancesSettingsView: View {
|
||||
}
|
||||
|
||||
var selectedInstance: Instance! {
|
||||
model.find(selectedInstanceID)
|
||||
InstancesModel.find(selectedInstanceID)
|
||||
}
|
||||
|
||||
private var selectedInstanceAccounts: [Instance.Account] {
|
||||
@@ -124,7 +139,7 @@ struct InstancesSettingsView: View {
|
||||
return []
|
||||
}
|
||||
|
||||
return model.accounts(selectedInstanceID)
|
||||
return InstancesModel.accounts(selectedInstanceID)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user