Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions e2e/phone.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AxeBuilder from "@axe-core/playwright";
import { expect, test, type Page } from "./local-test";
import { openFixture } from "./next-fixture";

Expand Down Expand Up @@ -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([]);
});
1 change: 1 addition & 0 deletions src/app/open-problem-details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
26 changes: 13 additions & 13 deletions src/app/use-calendar-agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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<HTMLElement>(".agenda-strip-weekday");
if (!weekday) {
Expand All @@ -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<HTMLElement>(".agenda-strip-count");
if (!badge) {
badge = document.createElement("span");
Expand Down Expand Up @@ -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<HTMLElement>(".tnc-list-more");
if (sentinel) {
let more = host!.querySelector<HTMLButtonElement>(".agenda-load-more");
Expand Down
10 changes: 8 additions & 2 deletions src/calendar-service/use-calendar-service.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
23 changes: 18 additions & 5 deletions src/calendar-service/use-calendar-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
import {
useEffect,
useMemo,
useRef,
useState,
useSyncExternalStore,
} from "react";
import {
calendarServiceClient,
CalendarServiceError,
Expand Down Expand Up @@ -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<LoadedEvents | null>(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();
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 24 additions & 3 deletions src/styles/16-scratchpad-live-preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
52 changes: 47 additions & 5 deletions src/styles/17-scratchpad-note.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}

Expand Down
Loading