2024-06-19 15:15:27 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SettingsScreen: View {
|
2024-10-04 15:58:04 +00:00
|
|
|
@EnvironmentObject var clientsStore: ClientsStore
|
2024-10-07 15:21:26 +00:00
|
|
|
@Environment(\.router) var router
|
2024-10-04 15:58:04 +00:00
|
|
|
|
2024-06-19 15:15:27 +00:00
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
2024-10-07 12:54:07 +00:00
|
|
|
// Background color
|
2024-07-04 08:21:12 +00:00
|
|
|
Color.Material.Background.light
|
2024-06-19 15:15:27 +00:00
|
|
|
.ignoresSafeArea()
|
|
|
|
|
2024-10-07 12:54:07 +00:00
|
|
|
// Content
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
// Header
|
|
|
|
SharedNavigationBar(
|
|
|
|
centerText: .init(text: L10n.Settings.Main.title)
|
|
|
|
)
|
|
|
|
|
|
|
|
// List
|
|
|
|
List {
|
|
|
|
// Accounts section
|
|
|
|
SharedSectionTitle(text: L10n.Settings.Section.Accounts.title)
|
|
|
|
|
2024-10-15 17:47:51 +00:00
|
|
|
ForEach(clientsStore.clients) { client in
|
|
|
|
SharedListRow(
|
|
|
|
iconType: .charCircle(client.credentials.bareJid),
|
|
|
|
text: client.credentials.bareJid,
|
|
|
|
controlType: .switcher(isOn: Binding(
|
|
|
|
get: { client.credentials.isActive },
|
|
|
|
set: { new in
|
|
|
|
Task {
|
|
|
|
try? await client.credentials.setActive(flag: new)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
))
|
|
|
|
)
|
|
|
|
.onTapGesture {
|
|
|
|
print("Tapped account \(client.credentials.bareJid)")
|
|
|
|
}
|
|
|
|
}
|
2024-10-07 12:54:07 +00:00
|
|
|
|
|
|
|
SharedListRow(
|
2024-10-07 15:09:55 +00:00
|
|
|
iconType: .image(Image(systemName: "plus"), .Material.Elements.active),
|
|
|
|
text: L10n.Settings.Section.Accounts.add,
|
2024-10-07 12:54:07 +00:00
|
|
|
controlType: .none
|
|
|
|
)
|
|
|
|
.onTapGesture {
|
2024-10-07 15:21:26 +00:00
|
|
|
router.showAlert(
|
|
|
|
.confirmationDialog,
|
|
|
|
title: L10n.Settings.Section.Accounts.add,
|
|
|
|
subtitle: L10n.Settings.Section.Accounts.addHint
|
|
|
|
) {
|
|
|
|
addAccountSelector
|
|
|
|
}
|
2024-10-07 12:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dev section
|
|
|
|
#if DEBUG
|
|
|
|
SharedSectionTitle(text: "Dev tools")
|
|
|
|
|
|
|
|
SharedListRow(
|
2024-10-07 15:09:55 +00:00
|
|
|
iconType: .image(Image(systemName: "xmark.octagon"), .Rainbow.red500),
|
2024-10-07 12:54:07 +00:00
|
|
|
text: "Clean all data",
|
|
|
|
controlType: .none
|
|
|
|
)
|
|
|
|
.onTapGesture {
|
2024-10-07 16:16:00 +00:00
|
|
|
router.showAlert(
|
|
|
|
.alert,
|
|
|
|
title: "Delete data",
|
|
|
|
subtitle: "Delete all data from the app?"
|
|
|
|
) {
|
|
|
|
Button("Delete", role: .destructive) {
|
|
|
|
clientsStore.flushAllData()
|
|
|
|
Database.shared.flushAllData()
|
2024-10-07 16:58:02 +00:00
|
|
|
UserSettings.reset()
|
2024-10-07 16:16:00 +00:00
|
|
|
}
|
|
|
|
}
|
2024-10-07 12:54:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
2024-10-04 15:58:04 +00:00
|
|
|
}
|
2024-10-07 12:54:07 +00:00
|
|
|
.listStyle(.plain)
|
|
|
|
.environment(\.defaultMinListRowHeight, 10)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
2024-10-15 11:39:23 +00:00
|
|
|
// .onDisappear {
|
|
|
|
// if settingsStore.credentials.isEmpty || settingsStore.credentials.allSatisfy({ !$0.isActive }) {
|
|
|
|
// router.dismissScreenStack()
|
|
|
|
// }
|
|
|
|
// }
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
2024-10-07 15:21:26 +00:00
|
|
|
|
|
|
|
@ViewBuilder private var addAccountSelector: some View {
|
|
|
|
Button {
|
|
|
|
print("Add existing account")
|
|
|
|
} label: {
|
|
|
|
Text(L10n.Settings.Section.Accounts.addExists)
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
print("Add new account")
|
|
|
|
} label: {
|
|
|
|
Text(L10n.Settings.Section.Accounts.addNew)
|
|
|
|
}
|
|
|
|
|
|
|
|
Button(role: .cancel) {} label: {
|
|
|
|
Text(L10n.Global.cancel)
|
|
|
|
}
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|