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: an all-day bar's ends stretch it over more days
Yashwanth Kamireddic7486741e56d
diff --git a/.uiverify/calendar-undo.mjs b/.uiverify/calendar-undo.mjsindex 3b79749..64f2198 100644--- a/.uiverify/calendar-undo.mjs+++ b/.uiverify/calendar-undo.mjs@@ -88,6 +88,23 @@ ok(await opened.isVisible(), "a click on the bar opens it");await page.keyboard.press("Escape");await opened.waitFor({ state: "detached" });+// Its end stretched a day on (or, on the week's last day, its start a day back).+const ends = await bar.boundingBox();+const grabX = by === 1 ? ends.x + ends.width - 2 : ends.x + 2;+await page.mouse.move(grabX, ends.y + ends.height / 2);+await page.mouse.down();+await page.mouse.move(grabX + (by * colWidth) / 2, ends.y + ends.height / 2, { steps: 3 });+await page.mouse.move(grabX + by * colWidth, ends.y + ends.height / 2, { steps: 4 });+const stretched = await bar.boundingBox();+ok(Math.abs(stretched.width - ends.width - colWidth) < 4, `the bar stretches with the pointer [${Math.round(stretched.width - ends.width)}]`);+await page.mouse.up();+await savesReach(3);+s = await saves();+const [wantFrom, wantTo] = by === 1 ? [start, await midnightIn(2)] : [await midnightIn(-1), await midnightIn(1)];+ok(s.length === 3 && s[2].guid === "ad1" && s[2].startsAt === wantFrom && s[2].endsAt === wantTo,+ `stretched, it spans two days ${JSON.stringify(s[2] && { g: s[2].guid, from: (s[2].startsAt - start) / 3600, to: (s[2].endsAt - start) / 3600 })}`);+ok(await page.getByRole("dialog").count() === 0, "a stretched bar does not open");+// Deleted from the keyboard, then Ctrl+Z makes it again.await page.locator(".cx-block", { hasText: "Dentist" }).click();await page.getByRole("dialog", { name: "Dentist" }).waitFor();@@ -96,10 +113,10 @@ await page.keyboard.press("Delete");await page.getByRole("button", { name: "Delete", exact: true }).click();await page.waitForFunction(() => (window.__eventDeletes ?? []).length === 1);await page.keyboard.press("Control+z");-await savesReach(3);+await savesReach(4);s = await saves();-ok(s.length === 3 && s[2].guid === null && s[2].title === "Dentist" && JSON.stringify(s[2].alerts) === "[15]",- `Ctrl+Z makes the deleted event again, its alert with it ${JSON.stringify(s[2] && { g: s[2].guid, t: s[2].title, a: s[2].alerts })}`);+ok(s.length === 4 && s[3].guid === null && s[3].title === "Dentist" && JSON.stringify(s[3].alerts) === "[15]",+ `Ctrl+Z makes the deleted event again, its alert with it ${JSON.stringify(s[3] && { g: s[3].guid, t: s[3].title, a: s[3].alerts })}`);// An event that ends as it starts keeps no length when its title is changed.await page.locator(".cx-block", { hasText: "Forms due" }).click();@@ -108,9 +125,9 @@ await deadline.waitFor();await deadline.getByLabel("Title").fill("Forms in");// Named by its title, the dialog is "Forms in" now.await page.getByRole("dialog", { name: "Forms in" }).getByRole("button", { name: "Save" }).click();-await savesReach(4);+await savesReach(5);s = await saves();-ok(s.length === 4 && s[3].guid === "dl1" && s[3].endsAt === s[3].startsAt, `a deadline stays a moment ${JSON.stringify(s[3] && { g: s[3].guid, len: s[3].endsAt - s[3].startsAt })}`);+ok(s.length === 5 && s[4].guid === "dl1" && s[4].endsAt === s[4].startsAt, `a deadline stays a moment ${JSON.stringify(s[4] && { g: s[4].guid, len: s[4].endsAt - s[4].startsAt })}`);await b.close();console.log(failures ? `${failures} failed` : "all passed");diff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsxindex f889191..9d96b94 100644--- a/src/screens/calendar/CalendarView.tsx+++ b/src/screens/calendar/CalendarView.tsx@@ -2324,9 +2324,10 @@ type Drag =/** Dragging an event's bottom edge: its end moves, its start stays — or, by its top edge* (`top`), its start moves and its end stays. */| { kind: "resize"; event: CalendarEvent; startY: number; dMinutes: number; top?: boolean }- /** A bar in the all-day row carried to other days: `from` is its first column shown, and- * `dx` how many days it has been carried. */- | { kind: "days"; event: CalendarEvent; from: number; startX: number; dx: number };+ /** A bar in the all-day row carried to other days: `from` and `to` are its first and last+ * columns shown, and `dx` how many days it has been carried — or, by one of its ends+ * (`edge`), how many days that end has been stretched. */+ | { kind: "days"; event: CalendarEvent; from: number; to: number; startX: number; dx: number; edge?: "start" | "end" };const TimeGrid = memo(function TimeGrid({days,@@ -2454,8 +2455,14 @@ const TimeGrid = memo(function TimeGrid({} else if (current.kind === "days") {const el = columnsEl.current;const width = el ? el.getBoundingClientRect().width / days.length : 1;- // Its first day shown kept on the screen, as a timed event is.- const dx = Math.min(days.length - 1 - current.from, Math.max(-current.from, Math.round((clientX - current.startX) / width)));+ // Its first day shown kept on the screen, as a timed event is; stretched, an end never+ // past the other one.+ const want = Math.round((clientX - current.startX) / width);+ const dx = current.edge === "end"+ ? Math.min(days.length - 1 - current.to, Math.max(current.from - current.to, want))+ : current.edge === "start"+ ? Math.min(current.to - current.from, Math.max(-current.from, want))+ : Math.min(days.length - 1 - current.from, Math.max(-current.from, want));if (dx === current.dx) return;next = { ...current, dx };} else {@@ -2487,7 +2494,11 @@ const TimeGrid = memo(function TimeGrid({window.setTimeout(() => (swallowClick.current = false), 0);// Whole days on the event's own clock, never 86,400 seconds (model.ts).const zone = zoneOf(done.event);- onMove(done.event, addDaysIn(zone, done.event.startsAt, done.dx), addDaysIn(zone, done.event.endsAt, done.dx));+ onMove(+ done.event,+ done.edge === "end" ? done.event.startsAt : addDaysIn(zone, done.event.startsAt, done.dx),+ done.edge === "start" ? done.event.endsAt : addDaysIn(zone, done.event.endsAt, done.dx),+ );}} else if (done.kind === "resize") {if (done.dMinutes !== 0) {@@ -2662,8 +2673,15 @@ const TimeGrid = memo(function TimeGrid({>{spans.map((s) => {const carried = drag?.kind === "days" && drag.event.guid === s.event.guid ? drag : null;- const from = s.from + (carried?.dx ?? 0);- const to = Math.min(s.to + (carried?.dx ?? 0), days.length - 1);+ const from = s.from + (carried && carried.edge !== "end" ? carried.dx : 0);+ const to = Math.min(s.to + (carried && carried.edge !== "start" ? carried.dx : 0), days.length - 1);+ const stretch = (edge: "start" | "end") => (e: React.PointerEvent) => {+ if (e.button !== 0) return;+ e.stopPropagation();+ e.preventDefault();+ setDragNow({ kind: "days", event: s.event, from: s.from, to: s.to, startX: e.clientX, dx: 0, edge });+ };+ const mine = canWrite(s.event.calendarGuid);return (<buttonkey={s.event.guid}@@ -2683,13 +2701,21 @@ const TimeGrid = memo(function TimeGrid({}// Carried to other days, as a bar in Month is; held still, a click opens it.onPointerDown={(e) => {- if (e.button !== 0 || days.length < 2 || !canWrite(s.event.calendarGuid)) return;+ if (e.button !== 0 || days.length < 2 || !mine) return;e.preventDefault();- setDragNow({ kind: "days", event: s.event, from: s.from, startX: e.clientX, dx: 0 });+ setDragNow({ kind: "days", event: s.event, from: s.from, to: s.to, startX: e.clientX, dx: 0 });}}onClick={(e) => !swallowClick.current && onOpen(s.event, { x: e.clientX, y: e.clientY })}>{s.event.title}+ {/* Its ends, to stretch it over more days or fewer, as in Calendar — where they+ are on screen. */}+ {mine && days.length > 1 && !s.continuesLeft && (+ <span className="cx-bar-grip is-start" aria-hidden="true" onPointerDown={stretch("start")} />+ )}+ {mine && days.length > 1 && !s.continuesRight && (+ <span className="cx-bar-grip is-end" aria-hidden="true" onPointerDown={stretch("end")} />+ )}</button>);})}diff --git a/src/styles/calendar.css b/src/styles/calendar.cssindex e566413..b1fadfb 100644--- a/src/styles/calendar.css+++ b/src/styles/calendar.css@@ -442,6 +442,9 @@.cx-block:focus-visible { outline: var(--focus-ring); outline-offset: 0; }.cx-block.is-moving { z-index: 3; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28); opacity: 0.94; }.cx-bar-event.is-moving { z-index: 3; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.24); cursor: grabbing; }+.cx-bar-grip { position: absolute; top: 0; bottom: 0; width: 6px; cursor: ew-resize; }+.cx-bar-grip.is-start { left: 0; }+.cx-bar-grip.is-end { right: 0; }.cx-block.is-draft {--cal: var(--sys-blue);left: 0;