Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Calendar: making an event works the way Calendar does, and the grid reads right
Yashwanth Kamireddi0da892ed212c
diff --git a/.uiverify/calendar.mjs b/.uiverify/calendar.mjsindex d8f89ca..2ee7f36 100644--- a/.uiverify/calendar.mjs+++ b/.uiverify/calendar.mjs@@ -17,8 +17,10 @@ await ctx.addInitScript(() => {if (cmd === "auth_resume") return true;if (cmd === "account_services") return ["calendar"];if (cmd === "calendar_list") return [{ guid: "c", title: "Home", colour: "#0088FF", ctag: null, sortOrder: 0, enabled: true, writable: true, isDefault: true }];- if (cmd === "calendar_events") return [];- if (cmd === "reminders_due_between") return [r("a", "Pick up the parcel", at(8)), r("b", "Water the plants", at(8))];+ if (cmd === "calendar_events") return [{ guid: "e", calendarGuid: "c", title: "New Event", location: null,+ startsAt: at(19), endsAt: at(19, 15), allDay: false, timezone: null, url: null, notes: null, etag: null }];+ if (cmd === "reminders_due_between") return [r("a", "Pick up the parcel", at(8)), r("b", "Water the plants", at(8)),+ { ...r("d", "Done already", at(16)), completedAt: at(16) }];if (cmd === "calendar_sync") return { calendars: 1, events: 0 };if (cmd === "sync_all" || cmd === "sync_status") return { services: [], asOf: 1, tookMs: 0 };if (cmd === "plugin:event|listen") return 0;@@ -27,7 +29,7 @@ await ctx.addInitScript(() => {};});const page = await ctx.newPage();-await page.clock.setFixedTime(new Date(2026, 8, 29, 21, 51));+await page.clock.setFixedTime(new Date(2026, 8, 29, 22, 18));await page.goto("http://localhost:4173", { waitUntil: "networkidle" });await page.getByRole("button", { name: "Day", exact: true }).click();await page.waitForSelector(".cal-hours.is-day");@@ -51,5 +53,60 @@ const covered = await page.evaluate(() => {});ok(covered.length === 0, "the time of now never sits over an hour's label", `now covers ${JSON.stringify(covered)}`);+const done = await page.locator(".cx-reminder", { hasText: "Done already" }).count();+ok(done === 0, "a completed reminder is not on the schedule", "a completed reminder is drawn on the day");++const short = await page.locator(".cx-block", { hasText: "New Event" }).evaluate((el) => {+ const box = el.getBoundingClientRect();+ const title = el.querySelector(".cx-block-title").getBoundingClientRect();+ return { box: [box.top, box.bottom], title: [title.top, title.bottom] };+});+ok(short.title[0] >= short.box[0] - 0.5 && short.title[1] <= short.box[1] + 0.5,+ "a quarter-hour event's title is whole inside its block", `the title is cut: ${JSON.stringify(short)}`);++const label = await page.evaluate(() => {+ const now = document.querySelector(".cx-now-label");+ const gutter = now.parentElement.getBoundingClientRect();+ const r = now.getBoundingClientRect();+ return { text: now.textContent, inside: r.left >= gutter.left - 0.5 && r.right <= gutter.right + 0.5, width: r.width };+});+ok(label.inside, `the time of now fits beside the grid [${label.text}]`, `the time of now is cut: ${JSON.stringify(label)}`);++await page.getByRole("button", { name: "Week", exact: true }).click();+await page.waitForTimeout(300);+const title = (await page.locator(".cx-title").innerText()).replace(/\s+/g, " ").trim();+ok(/Sep/.test(title) && /Oct/.test(title), `a week across two months is named for both [${title}]`,+ `the week of Sep 27 – Oct 3 is titled "${title}"`);++// Making an event, the way Calendar makes one.+{+ const col = await page.locator(".cx-column").nth(3).boundingBox();+ const hour = (h) => col.y + h * 48;+ await page.mouse.click(col.x + 30, hour(14));+ await page.waitForTimeout(250);+ ok((await page.locator(".cx-popover").count()) === 0, "a single click on empty time makes nothing",+ "a single click on empty time opened a new event");++ await page.mouse.move(col.x + 30, hour(14));+ await page.mouse.down();+ await page.mouse.move(col.x + 30, hour(15.5), { steps: 6 });+ await page.mouse.up();+ await page.waitForTimeout(300);+ const made = await page.evaluate(() => {+ const pop = document.querySelector(".cx-popover")?.getBoundingClientRect();+ const block = document.querySelector(".cx-block.is-draft")?.getBoundingClientRect();+ return { pop: pop && [pop.left, pop.right, pop.top, pop.bottom], block: block && [block.left, block.right, block.top, block.bottom] };+ });+ ok(Boolean(made.pop), "dragging over empty time makes an event and opens it", "a drag opened nothing");+ ok(Boolean(made.block), "the event being named stays on the grid where it was made", "the new event vanished from the grid");+ const covers = made.pop && made.block && made.pop[0] < made.block[1] && made.pop[1] > made.block[0]+ && made.pop[2] < made.block[3] && made.pop[3] > made.block[2];+ ok(!covers, "the popover sits beside the new event, not over it", `the popover covers it: ${JSON.stringify(made)}`);+ const fields = await page.locator(".cx-popover .cx-when input").evaluateAll((els) => els.map((e) => e.type));+ ok(JSON.stringify(fields) === JSON.stringify(["date", "time", "date", "time"]),+ "a start and an end, each a date and a time", `the popover's fields are ${JSON.stringify(fields)}`);+ await page.keyboard.press("Escape");+}+await b.close();process.exitCode = failures === 0 ? 0 : 1;diff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsxindex 34ae941..e27768d 100644--- a/src/screens/calendar/CalendarView.tsx+++ b/src/screens/calendar/CalendarView.tsx@@ -94,7 +94,9 @@ const weekdayShort = (d: Date) => d.toLocaleDateString(undefined, { weekday: "shconst tint = (c: Calendar | undefined) =>c?.colour && /^#[0-9a-f]{6}$/i.test(c.colour) ? c.colour : "var(--sys-blue)";-type Anchor = { x: number; y: number };+/** Where a popover opens: to the right of `x`, or to the left of `left` (or `x`) when the+ * window has no room on the right. */+type Anchor = { x: number; y: number; left?: number };export function CalendarView() {const today = useMemo(() => new Date(), []);@@ -167,7 +169,8 @@ export function CalendarView() {]);setEvents(Array.isArray(found) ? found : []);setCalendars(Array.isArray(cals) ? cals : []);- setDue(Array.isArray(reminders) ? reminders : []);+ // What is done is not on the schedule any more; Calendar hides completed reminders.+ setDue(Array.isArray(reminders) ? reminders.filter((r) => !r.completedAt) : []);setLoaded(true);}, [range]);@@ -346,6 +349,15 @@ export function CalendarView() {strong: selected.toLocaleDateString(undefined, { day: "numeric", month: "long" }),rest: `${selected.getFullYear()}`,};+ // A week across two months is named for both, as Calendar does: "Sep – Oct 2026".+ if (view === "week" && week[0].getMonth() !== week[6].getMonth()) {+ const short = (d: Date) => d.toLocaleDateString(undefined, { month: "short" });+ const sameYear = week[0].getFullYear() === week[6].getFullYear();+ return {+ strong: `${short(week[0])}${sameYear ? "" : ` ${week[0].getFullYear()}`} – ${short(week[6])}`,+ rest: String(week[6].getFullYear()),+ };+ }const base = view === "week" ? week[6] : selected;return {strong: base.toLocaleDateString(undefined, { month: "long" }),@@ -486,6 +498,11 @@ export function CalendarView() {setSelected(d);setView("day");}}+ pending={+ draft && !draft.guid && !draft.allDay+ ? { startsAt: draft.startsAt, endsAt: draft.endsAt, title: draft.title }+ : null+ }/>)}@@ -787,6 +804,7 @@ function TimeGrid({onCreate,onMove,onPickDay,+ pending,}: {days: Date[];today: Date;@@ -798,6 +816,8 @@ function TimeGrid({onCreate: (startsAt: number, endsAt: number, allDay: boolean, at: Anchor) => void;onMove: (e: CalendarEvent, startsAt: number, endsAt: number) => void;onPickDay: (d: Date) => void;+ /** A new event being named in the popover, held on the grid where it was made. */+ pending?: { startsAt: number; endsAt: number; title: string } | null;}) {const scroller = useRef<HTMLDivElement | null>(null);const columnsEl = useRef<HTMLDivElement | null>(null);@@ -826,6 +846,14 @@ function TimeGrid({return { column, minutes };};+ /** Beside the day column, not under the pointer: the popover must not cover the event. */+ const besideColumn = (column: number, y: number): Anchor => {+ const r = columnsEl.current?.getBoundingClientRect();+ if (!r) return { x: 0, y };+ const width = r.width / days.length;+ return { x: r.left + (column + 1) * width, y, left: r.left + column * width } as Anchor;+ };+const onColumnDown = (e: React.PointerEvent) => {if (e.button !== 0 || (e.target as HTMLElement).closest(".cx-block")) return;const at = where(e.clientX, e.clientY);@@ -857,10 +885,12 @@ function TimeGrid({const done = drag;setDrag(null);if (done.kind === "create") {- const base = seconds(done.day);- // A click without a drag is an hour, like double-clicking in Calendar.- const to = done.to - done.from <= 15 ? done.from + 60 : done.to;- onCreate(base + done.from * 60, base + to * 60, false, { x: e.clientX, y: e.clientY });+ // A click on empty time does nothing, as in Calendar — only a drag or a double-click+ // makes an event, so looking around the week never opens a form by accident.+ if (done.to - done.from > 15) {+ const base = seconds(done.day);+ onCreate(base + done.from * 60, base + done.to * 60, false, besideColumn(done.column, e.clientY));+ }} else if (done.dx !== 0 || done.dMinutes !== 0) {const shift = done.dMinutes * 60;const moved = (s: number) => {@@ -922,7 +952,9 @@ function TimeGrid({{Array.from({ length: 24 }, (_, h) =>// An hour the red "now" label sits over is left out, as Calendar does, rather// than drawn underneath it.- h === 0 || (todayColumn >= 0 && Math.abs(h * 60 - nowMinutes) < 12) ? null : (+ // Measured in pixels, since that is what overlaps: two labels about 14px tall+ // touch until they are 18px apart, whatever an hour is drawn as.+ h === 0 || (todayColumn >= 0 && (Math.abs(h * 60 - nowMinutes) / 60) * HOUR < 18) ? null : (<span key={h} style={{ top: `${h * HOUR}px` }}>{hourLabel(h)}</span>@@ -941,6 +973,14 @@ function TimeGrid({onPointerDown={onColumnDown}onPointerMove={onPointerMove}onPointerUp={onPointerUp}+ onDoubleClick={(e) => {+ if ((e.target as HTMLElement).closest(".cx-block")) return;+ const at = where(e.clientX, e.clientY);+ if (!at) return;+ const start = Math.min(snap(Math.floor(at.minutes / 30) * 30), 23 * 60);+ const base = seconds(days[at.column]);+ onCreate(base + start * 60, base + (start + 60) * 60, false, besideColumn(at.column, e.clientY));+ }}onPointerCancel={() => setDrag(null)}>{days.map((d, column) => (@@ -951,12 +991,12 @@ function TimeGrid({return (<buttonkey={p.event.guid}- className={`cx-block${moving ? " is-moving" : ""}`}+ className={`cx-block${moving ? " is-moving" : ""}${p.length < 45 ? " is-short" : ""}`}style={{"--cal": tint(c),top: `${((p.top + (moving?.dMinutes ?? 0)) / 60) * HOUR}px`,- height: `${Math.max((p.length / 60) * HOUR - 2, 18)}px`,+ height: `${Math.max((p.length / 60) * HOUR - 2, 20)}px`,left: `calc(${(p.column / p.columns) * 100}% + ${(moving?.dx ?? 0) * 100}%)`,width: `calc(${100 / p.columns}% - 3px)`,} as React.CSSProperties@@ -995,6 +1035,18 @@ function TimeGrid({{r.title}</span>))}+ {pending && !drag && sameDay(dateOf(pending.startsAt), d) && (+ <span+ className="cx-block is-draft"+ style={{+ top: `${((dateOf(pending.startsAt).getHours() * 60 + dateOf(pending.startsAt).getMinutes()) / 60) * HOUR}px`,+ height: `${Math.max(((pending.endsAt - pending.startsAt) / 3600) * HOUR - 2, 20)}px`,+ }}+ >+ <span className="cx-block-title">{pending.title.trim() || "New Event"}</span>+ <span className="cx-block-time">{clock(pending.startsAt)}</span>+ </span>+ )}{drag?.kind === "create" && drag.column === column && (<spanclassName="cx-block is-draft"@@ -1099,6 +1151,46 @@ function YearView({/* ---- the event popover ---------------------------------------------------------------- */+/** A date and, unless it is all day, a time — two compact fields, as Calendar lays them out. */+function When({+ at,+ allDay,+ editable,+ label,+ onChange,+}: {+ at: number;+ allDay: boolean;+ editable: boolean;+ label: string;+ onChange: (s: number) => void;+}) {+ const d = dateOf(at);+ const day = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;+ const time = `${pad(d.getHours())}:${pad(d.getMinutes())}`;+ return (+ <span className="cx-when">+ <input+ type="date"+ aria-label={`${label} date`}+ value={day}+ readOnly={!editable}+ onChange={(e) => e.target.value && onChange(fromLocalInput(`${e.target.value}T${time}`))}+ />+ {!allDay && (+ <input+ type="time"+ aria-label={`${label} time`}+ step={300}+ value={time}+ readOnly={!editable}+ onChange={(e) => e.target.value && onChange(fromLocalInput(`${day}T${e.target.value}`))}+ />+ )}+ </span>+ );+}+function EventPopover({draft,at,@@ -1131,7 +1223,7 @@ function EventPopover({const { width, height } = el.getBoundingClientRect();const gap = 12;let left = at.x + gap;- if (left + width > window.innerWidth - 8) left = Math.max(8, at.x - width - gap);+ if (left + width > window.innerWidth - 8) left = Math.max(8, (at.left ?? at.x) - width - gap);const top = Math.min(Math.max(8, at.y - 24), window.innerHeight - height - 8);setPos({ left, top });}, [at]);@@ -1197,33 +1289,29 @@ function EventPopover({}}/></label>- <label className="cx-pop-row">+ <div className="cx-pop-row"><span>starts</span>- <input- type={draft.allDay ? "date" : "datetime-local"}- value={toLocalInput(draft.startsAt, draft.allDay)}- readOnly={!editable}- onChange={(e) => {- if (!e.target.value) return;- const startsAt = fromLocalInput(e.target.value);- // Moving the start keeps the length, as Calendar does.- set({ startsAt, endsAt: startsAt + (draft.endsAt - draft.startsAt) });- }}+ <When+ at={draft.startsAt}+ allDay={draft.allDay}+ editable={editable}+ label="Starts"+ // Moving the start keeps the length, as Calendar does.+ onChange={(startsAt) => set({ startsAt, endsAt: startsAt + (draft.endsAt - draft.startsAt) })}/>- </label>- <label className="cx-pop-row">+ </div>+ <div className="cx-pop-row"><span>ends</span>- <input- type={draft.allDay ? "date" : "datetime-local"}- value={toLocalInput(draft.allDay ? draft.endsAt - 1 : draft.endsAt, draft.allDay)}- readOnly={!editable}- onChange={(e) => {- if (!e.target.value) return;- const end = fromLocalInput(e.target.value);- set({ endsAt: draft.allDay ? seconds(addDays(dateOf(end), 1)) : end });- }}+ <When+ at={draft.allDay ? draft.endsAt - 1 : draft.endsAt}+ allDay={draft.allDay}+ editable={editable}+ label="Ends"+ onChange={(end) =>+ set({ endsAt: draft.allDay ? seconds(addDays(midnight(dateOf(end)), 1)) : Math.max(end, draft.startsAt + 300) })+ }/>- </label>+ </div><div className="cx-pop-row cal-field"><span>calendar</span><Pickerdiff --git a/src/styles/calendar.css b/src/styles/calendar.cssindex 6b514ee..0511c74 100644--- a/src/styles/calendar.css+++ b/src/styles/calendar.css@@ -311,7 +311,8 @@/* ---- week and day ------------------------------------------------------------------ */.cal-hours { flex: 1; display: flex; flex-direction: column; min-height: 0; }-.cx-gutter { width: 56px; flex: none; }+/* Wide enough for "10:18 PM" in the red of now, which was cut to "0:18 PM" at 56px. */+.cx-gutter { width: 66px; flex: none; }.cx-grid-head,.cx-allday { display: flex; border-bottom: 1px solid var(--separator); }.cx-grid-head > .cal-col-head { flex: 1; }@@ -414,6 +415,9 @@background: color-mix(in srgb, var(--sys-blue) 26%, var(--bg));pointer-events: none;}+/* Under three quarters of an hour there is room for one line: the title, then the time. */+.cx-block.is-short { flex-direction: row; align-items: center; gap: 6px; padding-top: 1px; padding-bottom: 1px; }+.cx-block.is-short .cx-block-where { display: none; }.cx-block-title { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--t-11); font-weight: 600; }.cx-block-time,.cx-block-where { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-size: 10.5px; }@@ -507,7 +511,10 @@.cx-pop-rows { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-top: 1px solid var(--separator); border-bottom: 1px solid var(--separator); }.cx-pop-row { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; font-size: var(--t-13); }.cx-pop-row > span:first-child { color: var(--text-2); text-align: right; }-.cx-pop-row input[type="datetime-local"],+.cx-when { display: flex; gap: 6px; min-width: 0; }+.cx-when input[type="date"] { flex: 1 1 auto; min-width: 0; }+.cx-when input[type="time"] { flex: 0 0 auto; }+.cx-pop-row input[type="time"],.cx-pop-row input[type="date"] {padding: 3px 6px;border: 1px solid var(--field-edge);