Sources/OrgstarMobile/SettingsScreen.swift
53 lines · 2487 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: agenda)
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 /// The span and start day, worded as the Mac's Settings word the start.
41 private var agenda: String {
42 func days(_ count: Int) -> String { count == 1 ? "1 day" : "\(count) days" }
43 let offset = OrgPreferences.agendaStartOffset()
44 let start = offset == 0 ? "today" : offset < 0 ? "\(days(-offset)) before today" : "\(days(offset)) after today"
45 return "\(days(OrgPreferences.agendaSpan())), starting \(start)"
46 }
47
48 private var todoKeywords: String {
49 OrgPreferences.orgSettings().todoSequences.map { ($0.active.map(\.name) + ["|"] + $0.done.map(\.name)).joined(separator: " ") }
50 .joined(separator: "; ")
51 }
52}
53#endif