From b4cc1b3a5e9a630f4e327e1423906d644e672839 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sat, 28 Nov 2026 23:30:46 +1100 Subject: [PATCH] Give Scratchpad controls room for touch and avoid repeated agenda projection --- e2e/phone.spec.ts | 36 +++++++++++++ src/app/open-problem-details.test.tsx | 1 + src/app/use-calendar-agenda.ts | 26 +++++----- .../use-calendar-service.test.tsx | 10 +++- src/calendar-service/use-calendar-service.ts | 23 ++++++-- src/styles/16-scratchpad-live-preview.css | 27 ++++++++-- src/styles/17-scratchpad-note.css | 52 +++++++++++++++++-- 7 files changed, 147 insertions(+), 28 deletions(-) diff --git a/e2e/phone.spec.ts b/e2e/phone.spec.ts index 468384a4..dbeba9ac 100644 --- a/e2e/phone.spec.ts +++ b/e2e/phone.spec.ts @@ -1,3 +1,4 @@ +import AxeBuilder from "@axe-core/playwright"; import { expect, test, type Page } from "./local-test"; import { openFixture } from "./next-fixture"; @@ -316,3 +317,38 @@ test("touch long press selects, tap toggles, and swipes still act outside select await expect(selectedRows(page)).toHaveCount(1); await expect(page.getByRole("dialog")).toHaveCount(0); }); + +test("Scratchpad draft checkboxes own their full phone touch target", async ({ + page, +}) => { + await page.setViewportSize({ width: 390, height: 844 }); + await page.goto("scratchpad/?demo=60"); + const note = page.locator(".scratchpad-current-document"); + const box = note + .getByRole("checkbox", { name: "Mark task complete" }) + .first(); + await expect(box).toBeVisible(); + const bounds = (await box.boundingBox())!; + expect(bounds.width).toBeGreaterThanOrEqual(44); + expect(bounds.height).toBeGreaterThanOrEqual(44); + await expect + .poll(() => + box.evaluate((el) => { + const rect = el.getBoundingClientRect(); + return [1, 43].every((x) => + [1, 43].every( + (y) => + document.elementFromPoint(rect.left + x, rect.top + y) === el, + ), + ); + }), + ) + .toBe(true); + await box.tap({ position: { x: 1, y: 1 } }); + await expect( + note.getByRole("checkbox", { name: "Mark task incomplete" }).first(), + ).toBeChecked(); + await expect(box).not.toBeChecked(); + await expectNoHorizontalOverflow(page); + expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([]); +}); diff --git a/src/app/open-problem-details.test.tsx b/src/app/open-problem-details.test.tsx index b7c1a8e2..86dd96dc 100644 --- a/src/app/open-problem-details.test.tsx +++ b/src/app/open-problem-details.test.tsx @@ -35,6 +35,7 @@ it("names the code behind the generic copy, and nothing for actionable problems" developerMessage: describeError("internal")?.developerMessage ?? null, }); // Warnings and information already say what to do. + expect(openProblemReference(phase("open_in_another_tab"))).toBeNull(); expect(openProblemReference(phase("device_offline"))).toBeNull(); expect(openProblemReference(phase("setup_required"))).toBeNull(); }); diff --git a/src/app/use-calendar-agenda.ts b/src/app/use-calendar-agenda.ts index be904a8a..d23ea83d 100644 --- a/src/app/use-calendar-agenda.ts +++ b/src/app/use-calendar-agenda.ts @@ -2,7 +2,7 @@ import { calendarDateToInstant } from "@tasknotes/model/calendar"; import { t } from "@lingui/core/macro"; import { parseDay, type Calendar, type ItemArg } from "@tasknotes/calendar"; import { useEffect, useMemo, useRef, useState, type RefObject } from "react"; -import { appLocale } from "../i18n/app"; +import { dateFormatter } from "../i18n/date-formatter"; import { countLabel } from "../i18n/default-labels"; import { dateFromStorage, todayString, type TaskSummary } from "../domain/task"; import type { CalendarSettings } from "@tasknotes/model/calendar"; @@ -143,6 +143,14 @@ export function useCalendarAgenda({ : { start, end }, ); } + const fullDate = dateFormatter({ + weekday: "long", + month: "long", + day: "numeric", + year: "numeric", + }); + const shortWeekday = dateFormatter({ weekday: "short" }); + const today = todayString(new Date(), zone); for (const cell of cells) { const value = cell.dataset.date ?? ""; const day = parseDay(value); @@ -154,18 +162,12 @@ export function useCalendarAgenda({ (api.opts.allDaySlot || !modelEntry.allDay), ).length; const date = new Date(`${value}T12:00:00`); - const label = new Intl.DateTimeFormat(appLocale(), { - weekday: "long", - month: "long", - day: "numeric", - year: "numeric", - }).format(date); + const label = fullDate.format(date); cell.setAttribute( "aria-label", t`${label}, ${countLabel(count, "task")}`, ); - if (value === todayString(new Date(), zone)) - cell.setAttribute("aria-current", "date"); + if (value === today) cell.setAttribute("aria-current", "date"); else cell.removeAttribute("aria-current"); let weekday = cell.querySelector(".agenda-strip-weekday"); if (!weekday) { @@ -174,9 +176,7 @@ export function useCalendarAgenda({ weekday.setAttribute("aria-hidden", "true"); cell.prepend(weekday); } - weekday.textContent = new Intl.DateTimeFormat(appLocale(), { - weekday: "short", - }).format(date); + weekday.textContent = shortWeekday.format(date); let badge = cell.querySelector(".agenda-strip-count"); if (!badge) { badge = document.createElement("span"); @@ -233,7 +233,7 @@ export function useCalendarAgenda({ badge.hidden = count === 0; badge.setAttribute("aria-label", countLabel(count, "task")); } - compactAgendaDays(host!, selected, locale, todayString(new Date(), zone)); + compactAgendaDays(host!, selected, locale, today); const sentinel = host!.querySelector(".tnc-list-more"); if (sentinel) { let more = host!.querySelector(".agenda-load-more"); diff --git a/src/calendar-service/use-calendar-service.test.tsx b/src/calendar-service/use-calendar-service.test.tsx index a7bab660..008f283e 100644 --- a/src/calendar-service/use-calendar-service.test.tsx +++ b/src/calendar-service/use-calendar-service.test.tsx @@ -69,12 +69,18 @@ describe("events of the selected calendars", () => { expect(result.current.failure).toBe("rate_limited"); }); - it("reports no failure when every calendar is read", async () => { + it("keeps the event projection on rerender before and after a successful read", async () => { events.mockImplementation((id: string) => Promise.resolve({ events: [event(id)], omitted: 0 }), ); - const { result } = renderHook(() => useGoogleEvents(range)); + const { result, rerender } = renderHook(() => useGoogleEvents(range)); + const loading = result.current.events; + rerender(); + expect(result.current.events).toBe(loading); await waitFor(() => expect(result.current.events).toHaveLength(2)); + const shown = result.current.events; + rerender(); + expect(result.current.events).toBe(shown); expect(result.current.failure).toBeNull(); }); diff --git a/src/calendar-service/use-calendar-service.ts b/src/calendar-service/use-calendar-service.ts index 3bd6cb91..4f77f362 100644 --- a/src/calendar-service/use-calendar-service.ts +++ b/src/calendar-service/use-calendar-service.ts @@ -1,4 +1,10 @@ -import { useEffect, useRef, useState, useSyncExternalStore } from "react"; +import { + useEffect, + useMemo, + useRef, + useState, + useSyncExternalStore, +} from "react"; import { calendarServiceClient, CalendarServiceError, @@ -47,8 +53,10 @@ export function useGoogleEvents(range: { start: Date; end: Date }) { const { sessionId, calendars, selected, busy } = useCalendarService(); const [revision, setRevision] = useState(0); const [loaded, setLoaded] = useState(null); - const known = new Set(calendars.map((calendar) => calendar.id)); - const visible = selected.filter((id) => known.has(id)); + const visible = useMemo(() => { + const known = new Set(calendars.map((calendar) => calendar.id)); + return selected.filter((id) => known.has(id)); + }, [calendars, selected]); const visibleKey = visible.join(); const start = range.start.getTime(); const end = range.end.getTime(); @@ -118,10 +126,15 @@ export function useGoogleEvents(range: { start: Date; end: Date }) { }, [sessionId, visibleKey]); const current = loaded?.sessionId === sessionId ? loaded : null; - return { - events: + // The calendar uses this list to decide when to rebuild its item projection. + const events = useMemo( + () => current?.events.filter((event) => visible.includes(event.calendar_id)) ?? [], + [current, visible], + ); + return { + events, omitted: current?.omitted ?? 0, failure: current?.failure ?? null, loading: Boolean(sessionId) && !busy && visible.length > 0 && !current, diff --git a/src/styles/16-scratchpad-live-preview.css b/src/styles/16-scratchpad-live-preview.css index 57c4776c..e8fa0e30 100644 --- a/src/styles/16-scratchpad-live-preview.css +++ b/src/styles/16-scratchpad-live-preview.css @@ -138,10 +138,31 @@ } @media (pointer: coarse) { + /* Give the button its own column. Only the centred 20px box is painted. */ .markdown-source-editor .cm-lp-task { - width: 20px; - height: 20px; - vertical-align: -4px; + width: 44px; + height: 44px; + vertical-align: middle; + border: 0; + border-radius: 0; + background: transparent; + } + + .markdown-source-editor .cm-lp-task::before { + position: absolute; + inset: 12px; + content: ""; + border: 1.75px solid var(--ink-muted); + border-radius: 5px; + } + + .markdown-source-editor .cm-lp-task[aria-checked="true"] { + background: transparent; + } + + .markdown-source-editor .cm-lp-task[aria-checked="true"]::before { + background: var(--accent); + border-color: var(--accent); } .cm-lp-table-menu .mdbase-menu-item { diff --git a/src/styles/17-scratchpad-note.css b/src/styles/17-scratchpad-note.css index 4c4c140f..5931c83b 100644 --- a/src/styles/17-scratchpad-note.css +++ b/src/styles/17-scratchpad-note.css @@ -101,7 +101,8 @@ .scratchpad-note-text .cm-scratch-item { --lp-list-indent: calc( - (var(--scratch-depth, 0) + 1) * var(--scratch-step) + var(--scratch-depth, 0) * var(--scratch-step) + + var(--scratch-marker-width, var(--scratch-step)) ) !important; } @@ -324,16 +325,57 @@ @media (pointer: coarse) { .scratchpad-note-text { - --scratch-line-pad: 7px; + --scratch-line-pad: 2px; + --scratch-marker-width: 44px; + } + + .scratchpad-note-text .cm-scratch-item { + min-height: 48px; + } + + .scratchpad-note-text .cm-gutters, + .scratchpad-note-text .cm-scratch-fold-gutter, + .scratchpad-note-text .cm-scratch-fold { + width: 44px; + } + + .scratchpad-note-text .cm-scratch-fold, + .cm-scratch-task-title, + .cm-scratch-folded, + .scratchpad-review-item label { + min-height: 44px; + min-width: 44px; + } + + .cm-scratch-fold, + .cm-scratch-create { + border-radius: 0; + } + + /* Keep the linked task's priority ring and extend its hit area inside + the same marker column as the draft checkbox. */ + .scratchpad-note-text .cm-scratch-task .cm-lp-bullet { + margin-inline-start: 13px; + } + + .scratchpad-note-text .cm-scratch-task .cm-lp-bullet::before { + position: absolute; + inset: 50% auto auto 50%; + width: 44px; + height: 44px; + content: ""; + transform: translate(-50%, -50%); + background: transparent; + border: 0; } .cm-scratch-create { - width: 36px; - height: 36px; + width: 44px; + height: 44px; } .scratchpad-note-text .cm-scratch-draft { - padding-right: 40px; + padding-right: 44px; } }