Agenda polish !184
6 files changed, +37 −37
Layout: unified · split
Sources/OrgPresentation/AgendaRows.swift +2 −2
| @@ -42,7 +42,7 @@ public struct AgendaEvent: Sendable, Equatable, Identifiable { | ||
| 42 | 42 | /// |
| 43 | 43 | /// The gutter holds the time (`08:00`, `13:50–14:30`) or, untimed, a short status: |
| 44 | 44 | /// deadlines `Due today`, `Due in 2d`, `3d late`, `Due` (on a day other than today); |
| 45 | /// scheduled `Scheduled`, `Sched. 4d ago`; habits `Habit`; timestamps, diary sexps and | |
| 45 | /// scheduled `Scheduled`, `4d ago`; habits `Habit`; timestamps, diary sexps and | |
| 46 | 46 | /// calendar events `All day`; ranges `Day 2/5`; log mode `Closed`, `Clocked`, `State`; TODO |
| 47 | 47 | /// and match lists nothing. Ages use `AgendaAge.compact`. |
| 48 | 48 | public struct AgendaRow: Sendable, Equatable, Identifiable { |
| @@ -115,7 +115,7 @@ public struct AgendaRow: Sendable, Equatable, Identifiable { | ||
| 115 | 115 | } else { |
| 116 | 116 | icon = .scheduled |
| 117 | 117 | let on = planning ?? day |
| 118 | untimed = on < day ? "Sched. \(AgendaAge.compact(day - on)) ago" : "Scheduled" | |
| 118 | untimed = on < day ? "\(AgendaAge.compact(day - on)) ago" : "Scheduled" | |
| 119 | 119 | } |
| 120 | 120 | status = late ? .overdue : .normal |
| 121 | 121 | case .timestamp, .sexp: |
Sources/Orgstar/AgendaView.swift +11 −7
| @@ -38,6 +38,8 @@ struct AgendaView: View { | ||
| 38 | 38 | /// The selected line: `day:index` (`day:o` + index in the overdue group), or `list:index`. |
| 39 | 39 | @State private var selection: String? |
| 40 | 40 | @State private var tick = 0 |
| 41 | /// The time the now line shows, kept to the minute while the agenda is open. | |
| 42 | @State private var now = Date() | |
| 41 | 43 | /// The view picker moved to the agenda for a followed timestamp, which sets its own days. |
| 42 | 44 | @State private var keepRequestedDays = false |
| 43 | 45 | @State private var message: String? |
| @@ -295,10 +297,12 @@ struct AgendaView: View { | ||
| 295 | 297 | } |
| 296 | 298 | .task { |
| 297 | 299 | loadViews() |
| 298 | // The time grid's "now" line and the day itself move on. | |
| 300 | // The now line moves each minute; a new day refreshes the statuses. | |
| 299 | 301 | while !Task.isCancelled { |
| 300 | try? await Task.sleep(for: .seconds(60)) | |
| 301 | tick += 1 | |
| 302 | let next = Calendar.current.nextDate(after: Date(), matching: DateComponents(second: 0), matchingPolicy: .nextTime) ?? Date().addingTimeInterval(60) | |
| 303 | try? await Task.sleep(for: .seconds(next.timeIntervalSinceNow)) | |
| 304 | now = Date() | |
| 305 | if Days.absolute(now, calendar: .current) != agenda.today { tick += 1 } | |
| 302 | 306 | } |
| 303 | 307 | } |
| 304 | 308 | } |
| @@ -325,12 +329,12 @@ struct AgendaView: View { | ||
| 325 | 329 | .padding(.horizontal, 16) |
| 326 | 330 | .padding(.vertical, 10) |
| 327 | 331 | } |
| 328 | let now = group.nowIndex(now: Self.hhmm(Date())) | |
| 332 | let nowAt = group.nowIndex(now: Self.hhmm(now)) | |
| 329 | 333 | ForEach(Array(group.rows.enumerated()), id: \.element.id) { index, row in |
| 330 | if index == now { nowLine } | |
| 334 | if index == nowAt { nowLine } | |
| 331 | 335 | rowView(Line(id: "\(group.day):\(index)", row: row, day: group.day)) |
| 332 | 336 | } |
| 333 | if let now, now == group.rows.count { nowLine } | |
| 337 | if let nowAt, nowAt == group.rows.count { nowLine } | |
| 334 | 338 | } |
| 335 | 339 | |
| 336 | 340 | private func header(@ViewBuilder _ content: () -> some View) -> some View { |
| @@ -400,7 +404,7 @@ struct AgendaView: View { | ||
| 400 | 404 | |
| 401 | 405 | private var nowLine: some View { |
| 402 | 406 | HStack(spacing: 6) { |
| 403 | Text(Date().formatted(.dateTime.hour(.twoDigits(amPM: .omitted)).minute())) | |
| 407 | Text(now.formatted(.dateTime.hour(.twoDigits(amPM: .omitted)).minute())) | |
| 404 | 408 | .font(.system(size: 10, weight: .semibold).monospacedDigit()) |
| 405 | 409 | .frame(width: AgendaRowView.gutterWidth, alignment: .leading) |
| 406 | 410 | Circle().frame(width: 6, height: 6) |
Sources/OrgstarMobile/AgendaScreen.swift +19 −8
| @@ -18,6 +18,8 @@ struct AgendaScreen: View { | ||
| 18 | 18 | @Environment(MobileModel.self) private var model |
| 19 | 19 | @Environment(\.colorScheme) private var colorScheme |
| 20 | 20 | @State private var tick = 0 |
| 21 | /// The time the now line shows, kept to the minute while the agenda is open. | |
| 22 | @State private var now = Date() | |
| 21 | 23 | @State private var views = AgendaViewLoader.builtIn |
| 22 | 24 | @State private var viewName = "Agenda" |
| 23 | 25 | @State private var filter = AgendaFilter() |
| @@ -173,6 +175,15 @@ struct AgendaScreen: View { | ||
| 173 | 175 | views = loaded.views |
| 174 | 176 | if let problem = loaded.problems.first { message = problem } |
| 175 | 177 | } |
| 178 | // The now line moves each minute; a new day refreshes the statuses. | |
| 179 | .task { | |
| 180 | while !Task.isCancelled { | |
| 181 | let next = Calendar.current.nextDate(after: Date(), matching: DateComponents(second: 0), matchingPolicy: .nextTime) ?? Date().addingTimeInterval(60) | |
| 182 | try? await Task.sleep(for: .seconds(next.timeIntervalSinceNow)) | |
| 183 | now = Date() | |
| 184 | if Days.absolute(now, calendar: .current) != agenda.today { tick += 1 } | |
| 185 | } | |
| 186 | } | |
| 176 | 187 | // Calendar access is asked for when calendar-events is turned on. |
| 177 | 188 | .task(id: model.settingsVersion) { |
| 178 | 189 | guard OrgPreferences.calendarEvents(), !CalendarEvents.isAuthorized else { return } |
| @@ -232,17 +243,17 @@ struct AgendaScreen: View { | ||
| 232 | 243 | if group.isEmpty { |
| 233 | 244 | Text("Nothing scheduled").font(.subheadline).foregroundStyle(.secondary) |
| 234 | 245 | } |
| 235 | let now = nowIndex(group) | |
| 246 | let nowAt = nowIndex(group) | |
| 236 | 247 | ForEach(Array(group.rows.enumerated()), id: \.element.id) { index, item in |
| 237 | if index == now { NowLine(color: todayColor) } | |
| 248 | if index == nowAt { NowLine(time: now, color: todayColor) } | |
| 238 | 249 | row(item, day: group.day) |
| 239 | 250 | } |
| 240 | if let now, now == group.rows.count { NowLine(color: todayColor) } | |
| 251 | if let nowAt, nowAt == group.rows.count { NowLine(time: now, color: todayColor) } | |
| 241 | 252 | } |
| 242 | 253 | } |
| 243 | 254 | |
| 244 | 255 | private func nowIndex(_ group: AgendaDayGroup) -> Int? { |
| 245 | let c = Calendar.current.dateComponents([.hour, .minute], from: Date()) | |
| 256 | let c = Calendar.current.dateComponents([.hour, .minute], from: now) | |
| 246 | 257 | return group.nowIndex(now: (c.hour ?? 0) * 100 + (c.minute ?? 0)) |
| 247 | 258 | } |
| 248 | 259 | |
| @@ -645,10 +656,9 @@ struct AgendaRowView: View { | ||
| 645 | 656 | Text(row.gutter) |
| 646 | 657 | .font(.caption.weight(.medium).monospacedDigit()) |
| 647 | 658 | .foregroundStyle(statusColor) |
| 648 | .lineLimit(2) | |
| 659 | .lineLimit(1) | |
| 649 | 660 | .allowsTightening(true) |
| 650 | .minimumScaleFactor(0.85) | |
| 651 | .fixedSize(horizontal: false, vertical: true) | |
| 661 | .minimumScaleFactor(0.8) | |
| 652 | 662 | } |
| 653 | 663 | } |
| 654 | 664 | } |
| @@ -673,11 +683,12 @@ struct AgendaRowView: View { | ||
| 673 | 683 | |
| 674 | 684 | /// The current time between timed rows, as Org's `now - - -` line. |
| 675 | 685 | struct NowLine: View { |
| 686 | let time: Date | |
| 676 | 687 | let color: Color |
| 677 | 688 | |
| 678 | 689 | var body: some View { |
| 679 | 690 | HStack(spacing: 6) { |
| 680 | Text(Date.now.formatted(date: .omitted, time: .shortened)) | |
| 691 | Text(time.formatted(date: .omitted, time: .shortened)) | |
| 681 | 692 | .font(.caption2.weight(.semibold).monospacedDigit()) |
| 682 | 693 | .foregroundStyle(color) |
| 683 | 694 | Circle().fill(color).frame(width: 6, height: 6) |
Sources/OrgstarMobile/CaptureScreen.swift +2 −17
| @@ -98,7 +98,7 @@ struct CaptureScreen: View { | ||
| 98 | 98 | context.now = request.day.map(Self.date) ?? Date() |
| 99 | 99 | switch Capture.fill(template.template, context: context, answers: answers) { |
| 100 | 100 | case .success(let filled): |
| 101 | let (filledText, cursor) = request.day.map { Self.scheduling(filled.text, cursor: filled.cursor, on: $0) } ?? (filled.text, filled.cursor) | |
| 101 | let (filledText, cursor) = request.day.map { Capture.scheduling(filled.text, cursor: filled.cursor, on: $0) } ?? (filled.text, filled.cursor) | |
| 102 | 102 | text = filledText |
| 103 | 103 | selection = TextSelection(insertionPoint: String.Index(utf16Offset: cursor, in: filledText)) |
| 104 | 104 | problem = nil |
| @@ -120,26 +120,11 @@ struct CaptureScreen: View { | ||
| 120 | 120 | return calendar.date(from: parts) ?? Date() |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | /// An entry captured from an agenda day is scheduled on it: a SCHEDULED line goes under | |
| 124 | /// the heading unless the template already gave the entry an active timestamp. The caret | |
| 125 | /// keeps its place in the text. | |
| 126 | static func scheduling(_ text: String, cursor: Int, on day: Int) -> (String, Int) { | |
| 127 | guard text.hasPrefix("*"), text.firstMatch(of: /<[0-9]{4}-[0-9]{2}-[0-9]{2}/) == nil else { return (text, cursor) } | |
| 128 | let d = Days.date(day) | |
| 129 | let weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][Days.weekday(day)] | |
| 130 | let line = String(format: "SCHEDULED: <%04d-%02d-%02d ", d.year, d.month, d.day) + weekday + ">" | |
| 131 | let utf16 = Array(text.utf16) | |
| 132 | let end = utf16.firstIndex(of: 10) ?? utf16.count | |
| 133 | let inserted = "\n" + line | |
| 134 | let result = String(decoding: utf16[..<end], as: UTF16.self) + inserted + String(decoding: utf16[end...], as: UTF16.self) | |
| 135 | return (result, cursor > end ? cursor + inserted.utf16.count : cursor) | |
| 136 | } | |
| 137 | ||
| 138 | 123 | private func file() { |
| 139 | 124 | guard let template else { return } |
| 140 | 125 | let now = Date() |
| 141 | 126 | let placed = template.resolved(workspace: workspace, session: session, clock: clock).flatMap { resolved in |
| 142 | session.capture(text, template: resolved.template, root: workspace.rootPaths.first, file: resolved.file, now: now) | |
| 127 | session.capture(text, template: resolved.template, root: workspace.rootPaths.first, file: resolved.file, now: request.day.map(Self.date) ?? now) | |
| 143 | 128 | } |
| 144 | 129 | switch placed { |
| 145 | 130 | case .failure(let error): |
Tests/OrgPresentationTests/AgendaRowsTests.swift +2 −2
| @@ -68,8 +68,8 @@ struct AgendaRowsTests { | ||
| 68 | 68 | #expect(row?.status == status, "\(title)", sourceLocation: sourceLocation) |
| 69 | 69 | #expect(row?.icon == icon, "\(title)", sourceLocation: sourceLocation) |
| 70 | 70 | } |
| 71 | check("Pay rent", "Sched. 4d ago", .overdue, .scheduled) | |
| 72 | check("Ancient chore", "Sched. 1y 4mo ago", .overdue, .scheduled) | |
| 71 | check("Pay rent", "4d ago", .overdue, .scheduled) | |
| 72 | check("Ancient chore", "1y 4mo ago", .overdue, .scheduled) | |
| 73 | 73 | check("Send forms", "3d late", .overdue, .deadline) |
| 74 | 74 | check("File taxes", "Due today", .dueSoon, .deadline) |
| 75 | 75 | check("Renew passport", "Due in 4d", .dueSoon, .deadline) |
docs/plans/2026-10-08-agenda-redesign.md +1 −1
| @@ -32,7 +32,7 @@ Timed rows show `08:00` or `13:50–14:30` (zero-padded, en dash; past midnight | ||
| 32 | 32 | | Deadline, on today, upcoming | `Due in 2d` | due-soon | |
| 33 | 33 | | Deadline, on another day | `Due` | overdue if before today, else normal | |
| 34 | 34 | | Scheduled | `Scheduled` | overdue if before today, else normal | |
| 35 | | Scheduled, carried to today | `Sched. 4d ago` | overdue | | |
| 35 | | Scheduled, carried to today | `4d ago` | overdue | | |
| 36 | 36 | | Habit | `Habit` | overdue if scheduled before today | |
| 37 | 37 | | Timestamp, diary sexp | `All day` | normal | |
| 38 | 38 | | Range, middle days | `Day 2/5` | normal | |