1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 23:00:32 +05:30
yattee/Shared/Settings/InstanceSettings.swift

98 lines
3.5 KiB
Swift
Raw Normal View History

2021-11-28 20:07:55 +05:30
import SwiftUI
struct InstanceSettings: View {
let instanceID: Instance.ID?
@State private var accountsChanged = false
@State private var presentingAccountForm = false
@State private var frontendURL = ""
var instance: Instance! {
InstancesModel.find(instanceID)
}
var body: some View {
List {
2022-01-06 20:32:53 +05:30
Section(header: Text("Accounts")) {
2021-11-28 20:07:55 +05:30
if instance.app.supportsAccounts {
ForEach(InstancesModel.accounts(instanceID), id: \.self) { account in
#if os(tvOS)
Button(account.description) {}
.contextMenu {
Button("Remove") { removeAccount(account) }
Button("Cancel", role: .cancel) {}
}
#else
ZStack {
NavigationLink(destination: EmptyView()) {
EmptyView()
}
.disabled(true)
.hidden()
HStack {
Text(account.description)
Spacer()
}
.contextMenu {
2022-01-06 20:32:53 +05:30
Button {
removeAccount(account)
} label: {
Label("Remove", systemImage: "trash")
}
2021-11-28 20:07:55 +05:30
}
}
#endif
}
.redrawOn(change: accountsChanged)
2022-01-06 20:32:53 +05:30
Button {
2021-11-28 20:07:55 +05:30
presentingAccountForm = true
2022-01-06 20:32:53 +05:30
} label: {
Label("Add Account...", systemImage: "plus")
2021-11-28 20:07:55 +05:30
}
.sheet(isPresented: $presentingAccountForm, onDismiss: { accountsChanged.toggle() }) {
AccountForm(instance: instance)
}
#if !os(tvOS)
.listStyle(.insetGrouped)
#endif
} else {
Text("Accounts are not supported for the application of this instance")
.foregroundColor(.secondary)
}
}
2022-01-06 20:32:53 +05:30
if instance.app.hasFrontendURL {
Section(header: Text("Frontend URL")) {
TextField(
"Frontend URL",
text: $frontendURL
)
.onAppear {
frontendURL = instance.frontendURL ?? ""
}
.onChange(of: frontendURL) { newValue in
InstancesModel.setFrontendURL(instance, newValue)
}
.labelsHidden()
.autocapitalization(.none)
.keyboardType(.URL)
}
}
2021-11-28 20:07:55 +05:30
}
#if os(tvOS)
.frame(maxWidth: 1000)
#elseif os(iOS)
.listStyle(.insetGrouped)
#endif
.navigationTitle(instance.description)
}
private func removeAccount(_ account: Account) {
AccountsModel.remove(account)
accountsChanged.toggle()
}
}