Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Calendar: Month's bars stay inside their week

Yashwanth Kamireddi9977cce28bdd
diff --git a/.uiverify/calendar-month-bars.mjs b/.uiverify/calendar-month-bars.mjs
new file mode 100644
index 0000000..cd11f74
--- /dev/null
+++ b/.uiverify/calendar-month-bars.mjs
@@ -0,0 +1,57 @@
+// Month's all-day and multi-day bars stay inside their week. In a short window a week has room
+// under its dates for a lane or two; the bars past that ran on over the weeks below, across their
+// dates and their own bars. Now only the lanes that fit are drawn, and each day counts the bars
+// it lost in its "N more" (which opens the day, every bar in its all-day row). With room, every
+// bar is drawn across exactly the days it covers.
+//
+// URL=http://localhost:4173 ENGINE=webkit node .uiverify/calendar-month-bars.mjs
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+
+for (const [width, height] of [[1300, 1200], [1300, 850], [1300, 520], [760, 600]]) {
+ const ctx = await b.newContext({ viewport: { width, height } });
+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, calendarFixture: true,
+ extraEvents: [
+ // From today, nine days: across into next week.
+ { guid: "m1", title: "Conference", hour: -9, length: 24 * 9, allDay: true },
+ { guid: "m2", title: "Trip", day: 1, hour: -9, length: 24 * 2, allDay: true },
+ { guid: "m3", title: "Two days", day: 2, hour: 1, length: 30 },
+ { guid: "m4", title: "Workshop", day: 1, hour: -9, length: 24 * 3, allDay: true },
+ ] });
+ const page = await ctx.newPage();
+ page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
+ await page.goto(process.env.URL ?? "http://localhost:4173", { waitUntil: "networkidle" });
+ await openScreen(page, "Calendar");
+ await page.keyboard.press("Control+3");
+ await page.locator(".cx-week").first().waitFor();
+ await page.waitForTimeout(500);
+ const r = await page.evaluate(() => {
+ const out = { spill: [], wrongDays: [], drawn: 0, more: 0 };
+ for (const week of document.querySelectorAll(".cx-week")) {
+ const wr = week.getBoundingClientRect();
+ const days = [...week.querySelectorAll(".cx-day")].map((d) => d.getBoundingClientRect());
+ for (const bar of week.querySelectorAll(".cx-bar-event")) {
+ out.drawn++;
+ const br = bar.getBoundingClientRect();
+ if (br.top < wr.top - 0.5 || br.bottom > wr.bottom + 0.5) out.spill.push(bar.textContent);
+ // Its ends inside the first and last day it covers, never past a day's edge.
+ const first = days.findIndex((d) => br.left >= d.left - 0.5 && br.left < d.right);
+ const last = days.findIndex((d) => br.right > d.left && br.right <= d.right + 0.5);
+ if (first < 0 || last < first) out.wrongDays.push(bar.textContent);
+ }
+ for (const m of week.querySelectorAll(".cx-more")) out.more += Number(/\d+/.exec(m.textContent)?.[0] ?? 0);
+ }
+ return out;
+ });
+ const label = `${width}×${height}`;
+ ok(r.spill.length === 0, `${label}: no bar runs out of its week ${JSON.stringify(r.spill)}`);
+ ok(r.wrongDays.length === 0, `${label}: each bar starts and ends inside a day it covers ${JSON.stringify(r.wrongDays)}`);
+ if (height === 1200) ok(r.drawn >= 9 && r.more === 0, `${label}: with room, every bar is drawn (${r.drawn} bars, ${r.more} more)`);
+ else ok(r.more > 0, `${label}: the bars that do not fit are counted in "N more" (${r.drawn} bars, ${r.more} more)`);
+ await ctx.close();
+}
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsx
index e78e3ef..3db79f9 100644
--- a/src/screens/calendar/CalendarView.tsx
+++ b/src/screens/calendar/CalendarView.tsx
@@ -2185,7 +2185,12 @@ const MonthView = memo(function MonthView({
</div>
<div className={`cal-grid${carry ? " is-carrying" : ""}`} role="grid" aria-label="Month" ref={grid}>
{weeks.map((row, w) => {
- const spans = weekSpans(events, row[0]);
+ const all = weekSpans(events, row[0]);
+ // Only the lanes that fit under the dates are drawn: in a short week the rest ran on
+ // over the weeks below. With any left over, one line stays free for "N more" — the
+ // day opens with every bar in its all-day row.
+ const fit = all.some((s) => s.lane >= rows) ? rows - 1 : rows;
+ const spans = all.filter((s) => s.lane < fit);
return (
<div className="cx-week" role="row" key={w}>
{row.map((day, i) => {
@@ -2193,15 +2198,17 @@ const MonthView = memo(function MonthView({
// Only the lanes of the bars that cross this day are kept clear in it: a bar
// at the end of the week had left the days before it room for nothing.
const lanesHere = Math.max(0, ...spans.filter((s) => s.from <= i && s.to >= i).map((s) => s.lane + 1));
+ // Bars over this day that did not fit are counted in its "N more".
+ const cut = all.filter((s) => s.lane >= fit && s.from <= i && s.to >= i).length;
const room = Math.max(0, rows - lanesHere);
// What fits, and when it does not, one line fewer so "N more" has a line too.
// As dots, a row of them fits in any cell.
const visible = dots
? list.slice(0, MOST_DOTS)
- : list.length > room
+ : list.length > room || cut
? list.slice(0, Math.max(0, room - 1))
: list;
- const more = list.length - visible.length;
+ const more = list.length - visible.length + cut;
const isSelected = sameDay(day, selected);
const cellIndex = w * 7 + i;
return (