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
119 changes: 119 additions & 0 deletions benchmarks/recurrence-scale.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { afterEach, expect, it, vi } from "vitest";
import { calendarItems } from "../src/app/calendar-items";
import { DemoTaskRepository } from "../src/demo/demo-task-repository";
import { calendarEvents } from "../src/domain/calendar-events";
import {
projectTodayTasks,
taskOccurrencesBetween,
} from "../src/domain/task-occurrence";
import { summarizeToday } from "../src/domain/today-summary";

afterEach(() => vi.useRealTimers());

it.runIf(process.env.TASKNOTES_BENCH_FORMATTING === "1")(
"measures Today, Inbox and Calendar projections with 10,000 recurring tasks",
async () => {
const now = "2026-11-04T12:00:00Z";
const today = now.slice(0, 10);
vi.useFakeTimers({ toFake: ["Date"] });
vi.setSystemTime(new Date(now));
const repository = new DemoTaskRepository(1, undefined, {
tasks: (model) =>
Array.from({ length: 12_000 }, (_, index) =>
model.create(
{
title: `Series ${index}`,
scheduled: index < 8_000 ? "2026-10-05" : undefined,
recurrence:
index >= 10_000
? undefined
: index % 2
? "FREQ=WEEKLY;BYDAY=MO,WE,FR"
: "FREQ=DAILY",
},
{
id: `series-${index}`,
now: new Date(Date.parse(now) - index * 3_600_000).toISOString(),
},
),
),
scratchpads: () => [],
});
const configuration = await repository.taskConfiguration();
const views = (await repository.listViews()).flatMap((doc) => doc.views);
const calendar = views.find((view) => view.id === "calendar")!;
const inbox = views.find((view) => view.id === "inbox")!;
const execution = await repository.executeView(calendar);
const tasks = await repository.listSummaries({
status: "all",
limit: 50_000,
});
const start = new Date("2026-10-25T00:00:00Z");
const end = new Date("2026-12-06T00:00:00Z");
const samples = {
todaySummary: [] as number[],
todayOccurrences: [] as number[],
inboxView: [] as number[],
rruleDateExpansion: [] as number[],
calendarOccurrences: [] as number[],
calendarProjection: [] as number[],
};
let counts = {};
for (let round = 0; round <= 7; round++) {
const measure = async <T>(
key: keyof typeof samples,
operation: () => T | Promise<T>,
) => {
const since = performance.now();
const result = await operation();
if (round) samples[key].push(Math.round(performance.now() - since));
return result;
};
const summary = await measure("todaySummary", () =>
summarizeToday(tasks, today),
);
const todayRows = await measure("todayOccurrences", () =>
projectTodayTasks(tasks, "2026-10-05", today, 100),
);
const inboxRows = await measure("inboxView", () =>
repository.executeView(inbox),
);
const recurring = tasks.filter((task) => task.recurrence);
await measure("rruleDateExpansion", () =>
recurring.reduce(
(total, task) =>
total +
taskOccurrencesBetween(task, "2026-10-25", "2026-12-05").length,
0,
),
);
const calendarRows = await measure("calendarOccurrences", () =>
calendarEvents(execution, start, end, tasks, {}, configuration),
);
const items = await measure(
"calendarProjection",
() =>
calendarItems(calendarRows, execution, "title", configuration).items,
);
counts = {
next: summary.next?.date,
today: todayRows.totalCount,
inbox: inboxRows.totalCount,
calendar: items.length,
};
expect(recurring).toHaveLength(10_000);
expect(tasks).toHaveLength(12_000);
expect(summary.next?.date).toBe("2026-11-05");
expect(inboxRows.totalCount).toBe(2_000);
expect(items.length).toBeGreaterThan(100_000);
}
const medianMs = Object.fromEntries(
Object.entries(samples).map(([key, values]) => [
key,
[...values].sort((a, b) => a - b)[3],
]),
);
console.log(JSON.stringify({ counts, medianMs, samples }));
},
180_000,
);
10 changes: 9 additions & 1 deletion e2e/phone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,17 @@ test("touch month selection consumes its compatibility click, not the next inten
page,
}) => {
await page.emulateMedia({ colorScheme: "dark" });
await page.setViewportSize({ width: 412, height: 713 });
await page.setViewportSize({ width: 360, height: 713 });
await page.clock.setFixedTime(new Date("2026-11-06T10:00:00"));
await page.goto(route("calendar"));
for (const name of ["Previous period", "Next period"]) {
const bounds = await page
.getByRole("button", { name, exact: true })
.boundingBox();
expect(bounds?.width).toBeGreaterThanOrEqual(44);
expect(bounds?.height).toBeGreaterThanOrEqual(44);
}
await expectNoHorizontalOverflow(page);
const day = page.locator('.tnc-dg-day[data-date="2026-11-06"]');
await expect(day).toBeVisible();
await day.tap();
Expand Down
68 changes: 68 additions & 0 deletions e2e/projects-window.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect, test } from "./local-test";

test("Projects windows 125 groups and keeps offscreen jumps and row navigation", async ({
page,
}) => {
test.setTimeout(90_000);
await page.goto(
`views/${encodeURIComponent("TaskNotes/Views/projects.base#projects")}?demo=projects-scale`,
);
const project = (number: string) =>
page.getByRole("button", {
name: `Project ${number} 80 tasks`,
exact: true,
});
const task = (name: string) =>
page.getByRole("button", { name: `Task ${name}`, exact: true });
const rows = page.locator(".project-group .task-row");
await expect(task("001-01")).toBeVisible({ timeout: 30_000 });
expect(await rows.count()).toBeLessThan(100);
await expect(project("125")).toHaveCount(0);

const jump = page.getByRole("combobox", { name: "Jump to project" });
await jump.click();
await page
.getByRole("option", { name: "Project 125 (80)", exact: true })
.click();
const last = project("125");
await expect(last).toBeFocused();
await expect(last).toBeInViewport();
const controlsId = await last.getAttribute("aria-controls");
expect(controlsId).toMatch(/^\S+$/);
const controlled = page.locator(`[id="${controlsId}"]`);
await expect(
controlled.getByRole("button", { name: "Task 125-01", exact: true }),
).toBeVisible();
await last.press("Enter");
await expect(last).toHaveAttribute("aria-expanded", "false");
await expect(controlled).toBeHidden();
await last.press("Enter");
await expect(last).toHaveAttribute("aria-expanded", "true");
await expect(task("125-01")).toBeVisible();

await task("125-01").focus();
await task("125-01").press("ArrowUp");
await expect(task("124-80")).toBeFocused();
await task("124-80").press("Shift+ArrowDown");
await expect(task("125-01")).toBeFocused();
await expect(page.locator(".bulk-actions")).toContainText("2 selected");
await page.keyboard.press("Escape");

// A retained row must navigate to its true neighbour after a long scroll.
await page.evaluate(() => window.scrollTo(0, 0));
await expect(task("001-01")).toBeInViewport();
await expect(task("125-02")).toHaveCount(0);
await page.keyboard.press("ArrowDown");
await expect(task("125-02")).toBeFocused();
await expect(task("125-02")).toBeInViewport();
expect(await rows.count()).toBeLessThan(100);

await task("125-02").press("Enter");
await expect(page.getByRole("textbox", { name: "Task title" })).toHaveValue(
"Task 125-02",
);
await page.getByRole("button", { name: "Next task", exact: true }).click();
await expect(page.getByRole("textbox", { name: "Task title" })).toHaveValue(
"Task 125-03",
);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"test:watch": "vitest",
"bench:view-formatting": "TASKNOTES_BENCH_FORMATTING=1 vitest run benchmarks/view-formatting.test.ts benchmarks/view-entry.test.ts",
"bench:view-interactions": "TASKNOTES_BENCH_INTERACTIONS=1 vitest run benchmarks/view-interactions.test.ts",
"bench:recurrence": "TASKNOTES_BENCH_FORMATTING=1 vitest run benchmarks/recurrence-scale.test.ts",
"bench:collections": "tsc -p benchmarks/tsconfig.json && vitest run --config benchmarks/vitest.config.ts",
"test:e2e": "playwright test",
"test:e2e:connect": "playwright test --config playwright.dogfood.config.ts",
Expand Down
69 changes: 69 additions & 0 deletions scripts/bench-projects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* global history, location, PopStateEvent, dispatchEvent, requestAnimationFrame */
import assert from "node:assert/strict";
import { performance } from "node:perf_hooks";
import { chromium } from "@playwright/test";

const origin = new URL(process.argv[2] ?? "http://127.0.0.1:4173");
assert.ok(["localhost", "127.0.0.1"].includes(origin.hostname));
const browser = await chromium.launch();
try {
const context = await browser.newContext({
viewport: { width: 1280, height: 800 },
locale: "en-US",
timezoneId: "UTC",
reducedMotion: "reduce",
serviceWorkers: "block",
});
await context.route("**/*", (route) =>
new URL(route.request().url()).origin === origin.origin
? route.continue()
: route.abort(),
);
const page = await context.newPage();
await page.clock.setFixedTime(new Date("2026-11-04T12:00:00Z"));
await page.goto(new URL("/search?demo=projects-scale", origin).href);
const search = page.getByRole("searchbox", { name: "Search tasks" });
const projects =
"/views/" + encodeURIComponent("TaskNotes/Views/projects.base#projects");
const go = (path) =>
page.evaluate((next) => {
history.pushState(null, "", next + location.search);
dispatchEvent(new PopStateEvent("popstate"));
}, path);
const samples = [];
for (let round = 0; round <= 7; round++) {
await go("/search");
await search.waitFor();
const start = performance.now();
await go(projects);
await page
.locator(".project-group .task-row")
.first()
.waitFor({ timeout: 60_000 });
await page.evaluate(
() =>
new Promise((done) =>
requestAnimationFrame(() => requestAnimationFrame(done)),
),
);
const ms = Math.round(performance.now() - start);
const rows = await page.locator(".project-group .task-row").count();
if (round) samples.push({ ms, rows });
}
const median = (key) =>
samples.map((sample) => sample[key]).sort((a, b) => a - b)[3];
console.log(
JSON.stringify(
{
chromium: browser.version(),
medianMs: median("ms"),
medianRows: median("rows"),
samples,
},
null,
2,
),
);
} finally {
await browser.close();
}
2 changes: 1 addition & 1 deletion src/app/calendar-event-presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface CalendarPriorityMarker {
* completed work stays unmarked so titles keep the room.
*/
export function calendarPriorityMarker(
task: TaskSummary,
task: Pick<TaskSummary, "completed" | "priority">,
configuration: TaskCollectionConfiguration,
): CalendarPriorityMarker | undefined {
if (task.completed || !task.priority || task.priority === "none") return;
Expand Down
13 changes: 8 additions & 5 deletions src/app/calendar-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
calendarItem,
type CalendarEntry,
} from "../domain/calendar-events";
import { occurrenceTask, type TaskOccurrence } from "../domain/task-occurrence";
import { type TaskOccurrence } from "../domain/task-occurrence";
import type { TaskCollectionConfiguration } from "../domain/task-configuration";
import type { TaskViewExecution } from "../domain/view";
import {
Expand Down Expand Up @@ -114,9 +114,11 @@ export function calendarItems(
const neutral = entry.modelEntry;
if (seen.has(neutral.id)) continue;
seen.add(neutral.id);
const displayed = entry.occurrence
? occurrenceTask(entry.occurrence)
: entry.task;
const displayed = {
completed: entry.occurrence?.completed ?? entry.task.completed,
priority: entry.task.priority,
timezone: entry.task.timezone,
};
const tracked = neutral.type === "timeEntry";
const marker = tracked
? undefined
Expand Down Expand Up @@ -172,7 +174,8 @@ export function calendarItems(
details,
...(tracked
? { kind: "Tracked time" }
: neutral.type === "due" && displayed.scheduled
: neutral.type === "due" &&
(entry.occurrence || entry.task.scheduled)
? { kind: "Due" }
: {}),
recurring: Boolean(neutral.recurringKind),
Expand Down
12 changes: 12 additions & 0 deletions src/app/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FOCUS_ADJACENT_TASK } from "../components/bounded-list";
import { t } from "@lingui/core/macro";
import { hasOpenOverlay } from "../components/overlays/overlay-stack";
import { todayString } from "../domain/task";
Expand Down Expand Up @@ -240,6 +241,17 @@ export function focusAdjacentTaskRow(
const current = active?.closest<HTMLElement>(ROW_SELECTOR) ?? null;
const region =
current?.closest("#main-content, .detail-inspector") ?? main ?? document;
if (
current &&
!current.dispatchEvent(
new CustomEvent(FOCUS_ADJACENT_TASK, {
bubbles: true,
cancelable: true,
detail: direction,
}),
)
)
return true;
const rows = taskRowsIn(region);
if (!rows.length) return false;
if (!current || !rows.includes(current)) {
Expand Down
Loading
Loading