1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 14:20:32 +05:30
yattee/Shared/Settings/InstanceDetailsSettingsView.swift

71 lines
2.3 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import SwiftUI
struct InstanceDetailsSettingsView: View {
let instanceID: Instance.ID?
@State private var accountsChanged = false
@State private var presentingAccountForm = false
@EnvironmentObject<InstancesModel> private var instances
var instance: Instance! {
instances.find(instanceID)
}
var body: some View {
List {
Section(header: Text("Accounts")) {
ForEach(instances.accounts(instanceID)) { account in
2021-09-27 03:33:33 +05:30
HStack(spacing: 2) {
Text(account.description)
if instances.defaultAccount == account {
Text("— default")
.foregroundColor(.secondary)
}
}
2021-09-25 13:48:22 +05:30
#if !os(tvOS)
2021-09-27 03:33:33 +05:30
.swipeActions(edge: .leading, allowsFullSwipe: true) {
if instances.defaultAccount != account {
Button("Make Default", action: { makeDefault(account) })
} else {
Button("Reset Default", action: resetDefaultAccount)
2021-09-25 13:48:22 +05:30
}
}
2021-09-27 03:33:33 +05:30
.swipeActions(edge: .trailing, allowsFullSwipe: false) {
Button("Remove", role: .destructive, action: { removeAccount(account) })
}
2021-09-25 13:48:22 +05:30
#endif
}
.redrawOn(change: accountsChanged)
Button("Add account...") {
presentingAccountForm = true
}
}
}
#if os(iOS)
.listStyle(.insetGrouped)
#endif
.navigationTitle(instance.shortDescription)
.sheet(isPresented: $presentingAccountForm, onDismiss: { accountsChanged.toggle() }) {
AccountFormView(instance: instance)
}
}
2021-09-27 03:33:33 +05:30
private func makeDefault(_ account: Instance.Account) {
instances.setDefaultAccount(account)
accountsChanged.toggle()
}
private func resetDefaultAccount() {
instances.resetDefaultAccount()
accountsChanged.toggle()
}
private func removeAccount(_ account: Instance.Account) {
instances.removeAccount(account)
accountsChanged.toggle()
}
2021-09-25 13:48:22 +05:30
}