Sources/OrgstarMobile/SettingsScreen.swift

1d52ac3e828cb73639dc1c0cd5b6c9f0795b14a7
orgstar/Sources/OrgstarMobile/SettingsScreen.swift history · blame · raw

45 lines · 2110 bytes

 1#if os(iOS)
 2import OrgApp
 3import OrgCore
 4import SwiftUI
 5
 6/// Where settings come from: a folder with the Mac's `config.toml` and `capture.toml`, kept in
 7/// sync by iCloud Drive or another app.
 8struct SettingsScreen: View {
 9    let model: MobileModel
10    @State private var choosing = false
11
12    var body: some View {
13        Form {
14            Section {
15                LabeledContent("Folder", value: model.configFolder?.lastPathComponent ?? "None")
16                Button(model.configFolder == nil ? "Choose Folder…" : "Choose Another Folder…") { choosing = true }
17                if model.configFolder != nil {
18                    Button("Stop Using This Folder", role: .destructive) { model.setConfigFolder(nil) }
19                }
20                ForEach(model.configProblems, id: \.self) { Text($0).foregroundStyle(.red) }
21            } header: {
22                Text("Configuration")
23            } footer: {
24                Text("A folder with config.toml and capture.toml, such as a synced copy of ~/.config/orgstar from your Mac. Changes to them apply as they sync.")
25            }
26            Section("In use") {
27                let _ = model.settingsVersion
28                LabeledContent("TODO keywords", value: todoKeywords)
29                LabeledContent("Agenda", value: "\(OrgPreferences.agendaSpan()) days from \(OrgPreferences.agendaStartOffset())d")
30                LabeledContent("Reminders", value: OrgPreferences.reminders() ? "\(OrgPreferences.reminderLead()) min before" : "Off")
31                LabeledContent("Capture templates", value: CaptureTemplates.load().templates.map(\.key).joined(separator: " "))
32            }
33        }
34        .navigationTitle("Settings")
35        .fileImporter(isPresented: $choosing, allowedContentTypes: [.folder]) { result in
36            if case .success(let url) = result { model.setConfigFolder(url) }
37        }
38    }
39
40    private var todoKeywords: String {
41        OrgPreferences.orgSettings().todoSequences.map { ($0.active.map(\.name) + ["|"] + $0.done.map(\.name)).joined(separator: " ") }
42            .joined(separator: "; ")
43    }
44}
45#endif