Commit effed25309

effed253091f85af1d5121123f5681f855c07659

parent: 70bd2355be

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-10 19:27 UTC

iOS capture: date and tag sheets on the form

Presented from the entry's section, a row the form may not have in the window, the sheet waited and logged that its presenter wasn't in the window.

Layout: unified · split

Sources/OrgstarMobile/CaptureScreen.swift +28 −24
@@ -22,6 +22,9 @@ struct CaptureScreen: View {
2222 @State private var text = ""
2323 @State private var selection: TextSelection?
2424 @State private var problem: String?
25 /// The entry's date or tags sheet: on the form, not its section, which may not be in the window.
26 @State private var planning: EntryPlanning?
27 @State private var choosingTags = false
2528 @FocusState private var focused: Bool
2629
2730 private var template: CaptureTemplate? { templates.first { $0.key == key } }
@@ -42,7 +45,7 @@ struct CaptureScreen: View {
4245 if let problem { Text(problem).foregroundStyle(.red) }
4346 }
4447 if let entry = CaptureEntry(text: text, defaults: session.defaults) {
45 EntryFields(entry: entry, tagChoices: Array(Set(context.allTags + context.fileTags)).sorted(), change: change)
48 EntryFields(entry: entry, change: change, planning: $planning, choosingTags: $choosingTags)
4649 }
4750 } else {
4851 ForEach(questions.indices, id: \.self) { index in
@@ -51,6 +54,19 @@ struct CaptureScreen: View {
5154 if let problem { Text(problem).foregroundStyle(.red) }
5255 }
5356 }
57 .sheet(item: $planning) { which in
58 let entry = CaptureEntry(text: text, defaults: session.defaults)
59 DateTimeSheet(title: which.rawValue, initial: EntryFields.initial(which == .scheduled ? entry?.scheduled : entry?.deadline)) { answer in
60 planning = nil
61 if let answer { change(SetPlanning(deadline: which == .deadline), ["date": answer]) }
62 }
63 }
64 .sheet(isPresented: $choosingTags) {
65 TagsSheet(selected: CaptureEntry(text: text, defaults: session.defaults)?.tags ?? [], choices: Array(Set(context.allTags + context.fileTags)).sorted()) { tags in
66 choosingTags = false
67 if let tags { change(SetTags(), ["tags": tags.joined(separator: ":")]) }
68 }
69 }
5470 .navigationTitle("Capture")
5571 .navigationBarTitleDisplayMode(.inline)
5672 .toolbar {
@@ -220,18 +236,18 @@ struct QuestionField: View {
220236 return formatter.string(from: date)
221237 }
222238}
239/// Which date of the captured entry is being picked.
240private enum EntryPlanning: String, Identifiable {
241 case scheduled = "Scheduled", deadline = "Deadline"
242 var id: Self { self }
243}
244
223245/// The captured entry's keyword, priority, dates and tags, set without editing its text.
224246private struct EntryFields: View {
225247 let entry: CaptureEntry
226 let tagChoices: [String]
227248 let change: (any OrgCommand, [String: String]) -> Void
228 @State private var planning: Planning?
229 @State private var choosingTags = false
230
231 private enum Planning: String, Identifiable {
232 case scheduled = "Scheduled", deadline = "Deadline"
233 var id: Self { self }
234 }
249 @Binding var planning: EntryPlanning?
250 @Binding var choosingTags: Bool
235251
236252 var body: some View {
237253 Section {
@@ -254,21 +270,9 @@ private struct EntryFields: View {
254270 }
255271 .tint(.primary)
256272 }
257 .sheet(item: $planning) { which in
258 DateTimeSheet(title: which.rawValue, initial: initial(which == .scheduled ? entry.scheduled : entry.deadline)) { answer in
259 planning = nil
260 if let answer { change(SetPlanning(deadline: which == .deadline), ["date": answer]) }
261 }
262 }
263 .sheet(isPresented: $choosingTags) {
264 TagsSheet(selected: entry.tags, choices: tagChoices) { tags in
265 choosingTags = false
266 if let tags { change(SetTags(), ["tags": tags.joined(separator: ":")]) }
267 }
268 }
269273 }
270274
271 private func date(_ which: Planning, _ stamp: Timestamp?) -> some View {
275 private func date(_ which: EntryPlanning, _ stamp: Timestamp?) -> some View {
272276 Menu {
273277 Button("Today") { set(which, 0) }
274278 Button("Tomorrow") { set(which, 1) }
@@ -283,12 +287,12 @@ private struct EntryFields: View {
283287 .tint(.primary)
284288 }
285289
286 private func set(_ which: Planning, _ days: Int) {
290 private func set(_ which: EntryPlanning, _ days: Int) {
287291 let day = Calendar.current.date(byAdding: .day, value: days, to: Date()) ?? Date()
288292 change(SetPlanning(deadline: which == .deadline), ["date": QuestionField.stamp(day, withTime: false)])
289293 }
290294
291 private func initial(_ stamp: Timestamp?) -> Date {
295 static func initial(_ stamp: Timestamp?) -> Date {
292296 guard let stamp else { return Date() }
293297 let point = stamp.start
294298 return Calendar.current.date(from: DateComponents(year: point.year, month: point.month, day: point.day, hour: point.hour, minute: point.minute)) ?? Date()