import SwiftUI struct SettingsScreen: View { @EnvironmentObject var clientsStore: ClientsStore @Environment(\.router) var router var body: some View { ZStack { // Background color Color.Material.Background.light .ignoresSafeArea() // Content VStack(spacing: 0) { // Header SharedNavigationBar( centerText: .init(text: L10n.Settings.Main.title) ) // List List { // Accounts section SharedSectionTitle(text: L10n.Settings.Section.Accounts.title) // ForEach(settingsStore.credentials) { creds in // SharedListRow( // iconType: .charCircle(creds.bareJid), // text: creds.bareJid, // controlType: .switcher(isOn: Binding( // get: { creds.isActive }, // set: { new in // Task { // try? await creds.setActive(flag: new) // } // } // )) // ) // .onTapGesture { // print("Tapped account \(creds.bareJid)") // } // } SharedListRow( iconType: .image(Image(systemName: "plus"), .Material.Elements.active), text: L10n.Settings.Section.Accounts.add, controlType: .none ) .onTapGesture { router.showAlert( .confirmationDialog, title: L10n.Settings.Section.Accounts.add, subtitle: L10n.Settings.Section.Accounts.addHint ) { addAccountSelector } } // Dev section #if DEBUG SharedSectionTitle(text: "Dev tools") SharedListRow( iconType: .image(Image(systemName: "xmark.octagon"), .Rainbow.red500), text: "Clean all data", controlType: .none ) .onTapGesture { router.showAlert( .alert, title: "Delete data", subtitle: "Delete all data from the app?" ) { Button("Delete", role: .destructive) { clientsStore.flushAllData() Database.shared.flushAllData() UserSettings.reset() } } } #endif } .listStyle(.plain) .environment(\.defaultMinListRowHeight, 10) Spacer() } } // .onDisappear { // if settingsStore.credentials.isEmpty || settingsStore.credentials.allSatisfy({ !$0.isActive }) { // router.dismissScreenStack() // } // } } @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) } } }