yattee/Shared/Settings/InstanceSettings.swift

109 lines
3.9 KiB
Swift
Raw Normal View History

2021-11-28 14:37:55 +00:00
import SwiftUI
struct InstanceSettings: View {
let instance: Instance
2021-11-28 14:37:55 +00:00
@State private var accountsChanged = false
@State private var presentingAccountForm = false
@State private var frontendURL = ""
@State private var proxiesVideos = false
2021-11-28 14:37:55 +00:00
var body: some View {
List {
2022-09-04 15:28:30 +00:00
Section(header: Text("Accounts".localized())) {
2021-11-28 14:37:55 +00:00
if instance.app.supportsAccounts {
ForEach(InstancesModel.accounts(instance.id), id: \.self) { account in
2021-11-28 14:37:55 +00:00
#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 15:02:53 +00:00
Button {
removeAccount(account)
} label: {
Label("Remove", systemImage: "trash")
}
2021-11-28 14:37:55 +00:00
}
}
#endif
}
.redrawOn(change: accountsChanged)
2022-01-06 15:02:53 +00:00
Button {
2021-11-28 14:37:55 +00:00
presentingAccountForm = true
2022-01-06 15:02:53 +00:00
} label: {
Label("Add Account...", systemImage: "plus")
2021-11-28 14:37:55 +00:00
}
.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 15:02:53 +00:00
if instance.app.hasFrontendURL {
2022-09-04 15:28:30 +00:00
Section(header: Text("Frontend URL".localized())) {
2022-01-06 15:02:53 +00:00
TextField(
"Frontend URL",
text: $frontendURL
)
.onAppear {
frontendURL = instance.frontendURL ?? ""
}
.onChange(of: frontendURL) { newValue in
InstancesModel.setFrontendURL(instance, newValue)
}
.labelsHidden()
.autocapitalization(.none)
.keyboardType(.URL)
}
}
if instance.app.allowsDisablingVidoesProxying {
proxiesVideosToggle
.onAppear {
proxiesVideos = instance.proxiesVideos
}
.onChange(of: proxiesVideos) { newValue in
InstancesModel.setProxiesVideos(instance, newValue)
}
}
2021-11-28 14:37:55 +00:00
}
#if os(tvOS)
.frame(maxWidth: 1000)
#elseif os(iOS)
.listStyle(.insetGrouped)
#endif
.navigationTitle(instance.description)
}
private var proxiesVideosToggle: some View {
Toggle("Proxy videos", isOn: $proxiesVideos)
}
2021-11-28 14:37:55 +00:00
private func removeAccount(_ account: Account) {
AccountsModel.remove(account)
accountsChanged.toggle()
}
}