From 6966ecde2ec563be4da2a87f0576c4cd3255ad95 Mon Sep 17 00:00:00 2001
From: zasbu <136494048+zasbu@users.noreply.github.com>
Date: Fri, 6 Nov 2026 19:58:28 +1100
Subject: [PATCH 01/12] Move run age under the time on the activity table
---
web/src/features/activity/RecentRunTable.tsx | 63 +++++++++++---------
1 file changed, 34 insertions(+), 29 deletions(-)
diff --git a/web/src/features/activity/RecentRunTable.tsx b/web/src/features/activity/RecentRunTable.tsx
index 94358af..3f974ce 100644
--- a/web/src/features/activity/RecentRunTable.tsx
+++ b/web/src/features/activity/RecentRunTable.tsx
@@ -5,8 +5,8 @@ import { useState, type CSSProperties } from "react";
import { api, type Schemas } from "@/api/client";
import { RunLink } from "@/features/runs/RunLink";
import {
+ formatAge,
formatGap,
- formatSince,
formatTime,
trackName,
} from "@/features/runs/time";
@@ -86,7 +86,6 @@ export function RecentRunTable({
- WhenPlayerMapTime
@@ -107,12 +106,6 @@ export function RecentRunTable({
} as CSSProperties
}
>
-
- {/* Counted from now, which differs between the server's render and the browser's. */}
-
-
- {/* Against the record when the run finished: what a new WR took off, or how far behind it was. */}
- {run.gap != null && (
- 0
- ? "text-danger"
- : "text-text-subtle",
+
+
+
+ {formatTime(run.time)}
+
+ {/* Against the record when the run finished: what a new WR took off, or how far behind it was. */}
+ {run.gap != null && (
+ 0
+ ? "text-danger"
+ : "text-text-subtle",
+ )}
+ >
+ {run.gap < 0
+ ? `(−${formatTime(-run.gap)})`
+ : `(${formatGap(run.gap)})`}
+
)}
- >
- {run.gap < 0
- ? `−${formatTime(-run.gap)}`
- : formatGap(run.gap)}
- )}
-
- {formatTime(run.time)}
-
+ {/* Counted from now, which differs between the server's render and the browser's. */}
+
+
{run.world_record ? (
From 7e63acecc4a33f882b199b8fb48b5eb57c28440e Mon Sep 17 00:00:00 2001
From: zasbu <136494048+zasbu@users.noreply.github.com>
Date: Fri, 6 Nov 2026 20:09:25 +1100
Subject: [PATCH 02/12] Add replay buttons to the activity table and narrow the
page
---
web/src/app/activity/page.tsx | 2 +-
web/src/features/activity/RecentRunTable.tsx | 4 +-
web/src/features/replays/ReplayLink.tsx | 33 ++++++++++++++
web/src/features/replays/ReplayPlayer.tsx | 6 ++-
web/src/features/runs/RunDialogHost.tsx | 48 ++++++++++++++++++--
web/src/features/runs/runDialog.ts | 17 +++++--
web/src/ui/Dialog.tsx | 5 +-
web/src/ui/Page.tsx | 5 +-
8 files changed, 105 insertions(+), 15 deletions(-)
create mode 100644 web/src/features/replays/ReplayLink.tsx
diff --git a/web/src/app/activity/page.tsx b/web/src/app/activity/page.tsx
index b93150e..c7e864d 100644
--- a/web/src/app/activity/page.tsx
+++ b/web/src/app/activity/page.tsx
@@ -13,7 +13,7 @@ export const metadata: Metadata = {
export default function ActivityPage({ searchParams }: PageProps<"/activity">) {
return (
-
+
Activity
diff --git a/web/src/features/activity/RecentRunTable.tsx b/web/src/features/activity/RecentRunTable.tsx
index 3f974ce..88d42d2 100644
--- a/web/src/features/activity/RecentRunTable.tsx
+++ b/web/src/features/activity/RecentRunTable.tsx
@@ -3,6 +3,7 @@
// loads older runs a page at a time.
import { useState, type CSSProperties } from "react";
import { api, type Schemas } from "@/api/client";
+import { ReplayLink } from "@/features/replays/ReplayLink";
import { RunLink } from "@/features/runs/RunLink";
import {
formatAge,
@@ -144,7 +145,8 @@ export function RecentRunTable({
-
+
+ ) {
+ if (
+ event.metaKey ||
+ event.ctrlKey ||
+ event.shiftKey ||
+ event.altKey ||
+ event.button !== 0
+ ) {
+ return;
+ }
+ event.preventDefault();
+ openRun(runId, { replay: true });
+ }
+ return (
+
+
+
+ );
+}
diff --git a/web/src/features/replays/ReplayPlayer.tsx b/web/src/features/replays/ReplayPlayer.tsx
index e1ebbcb..e6b1741 100644
--- a/web/src/features/replays/ReplayPlayer.tsx
+++ b/web/src/features/replays/ReplayPlayer.tsx
@@ -70,17 +70,21 @@ type Prepared = { map: string; loading: ReturnType };
export function ReplayPlayer({
run,
styleNames,
+ startNow = false,
}: {
run: Schemas["RunDetail"];
/** Ranked styles' names by key, for a compared run of another style. */
styleNames: Record;
+ /** Start without waiting for a press, as in the replay dialog. */
+ startNow?: boolean;
}) {
const [pressedPhase, setPhase] = useState({ kind: "poster" });
- const autoStart = useSyncExternalStore(
+ const openedAtAnchor = useSyncExternalStore(
subscribeToHash,
openedAtReplay,
() => false,
);
+ const autoStart = startNow || openedAtAnchor;
const phase: Phase =
pressedPhase.kind === "poster" && autoStart
? { kind: "loading" }
diff --git a/web/src/features/runs/RunDialogHost.tsx b/web/src/features/runs/RunDialogHost.tsx
index a8b0241..edf8d75 100644
--- a/web/src/features/runs/RunDialogHost.tsx
+++ b/web/src/features/runs/RunDialogHost.tsx
@@ -2,6 +2,7 @@
// The run dialog, over whichever page is open. It opens the moment a run link is clicked and loads the run
// inside, so the page behind never reloads (lead, 2026-10-19). It shows what everyone sees; staff act on the
// run on its own page. Pre-2.0 runs open in it too, with what the old site kept; they have no run page.
+import dynamic from "next/dynamic";
import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { api, type Schemas } from "@/api/client";
@@ -12,7 +13,13 @@ import { Button, ButtonLink } from "@/ui/Button";
import { Dialog } from "@/ui/Dialog";
import { Tooltip } from "@/ui/Tooltip";
import { RunDetailList } from "./RunDetailList";
-import { closeRun, PRE_RUN_PARAM, RUN_PARAM } from "./runDialog";
+import { closeRun, PRE_RUN_PARAM, REPLAY_PARAM, RUN_PARAM } from "./runDialog";
+
+// The viewer is large, so it loads only once a replay is opened, not with every page.
+const ReplayPlayer = dynamic(
+ () => import("@/features/replays/ReplayPlayer").then((m) => m.ReplayPlayer),
+ { ssr: false },
+);
type Run =
| { legacy: false; run: Schemas["RunDetail"] }
@@ -52,10 +59,12 @@ async function loadRun(id: string, legacy: boolean): Promise {
export function RunDialogHost() {
const params = useSearchParams();
const runId = params.get(RUN_PARAM);
+ const replayId = params.get(REPLAY_PARAM);
const preRunId = params.get(PRE_RUN_PARAM);
- const id = runId ?? preRunId;
- const legacy = runId == null && preRunId != null;
- const key = id && `${legacy ? "pre" : "run"}-${id}`;
+ const id = runId ?? replayId ?? preRunId;
+ const replay = runId == null && replayId != null;
+ const legacy = runId == null && replayId == null && preRunId != null;
+ const key = id && `${legacy ? "pre" : replay ? "replay" : "run"}-${id}`;
const [loaded, setLoaded] = useState();
const [names, setNames] = useState
@@ -144,8 +148,8 @@ export function RecentRunTable({
-
-
+
+
)}
-
{/* Counted from now, which differs between the server's render and the browser's. */}
+
+
+
{run.world_record ? (
WR
From 7937b9ea284cd800394725e1a8f302ce07fdf46a Mon Sep 17 00:00:00 2001
From: zasbu <136494048+zasbu@users.noreply.github.com>
Date: Fri, 6 Nov 2026 20:20:23 +1100
Subject: [PATCH 05/12] Pull the replay button in close to the time and place
---
web/src/features/activity/RecentRunTable.tsx | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/web/src/features/activity/RecentRunTable.tsx b/web/src/features/activity/RecentRunTable.tsx
index 258f07a..08aa761 100644
--- a/web/src/features/activity/RecentRunTable.tsx
+++ b/web/src/features/activity/RecentRunTable.tsx
@@ -89,12 +89,14 @@ export function RecentRunTable({
PlayerMap
- Time
- {/* Both as narrow as their content, so the play button sits midway between the time and the place. */}
-
+
+ Time
+
+ {/* Narrow padding keeps the play button close to the time and the place. */}
+ Replay
-
+
Place
@@ -147,7 +149,7 @@ export function RecentRunTable({
)}
-
+
-
+
-
+
{run.world_record ? (
WR
) : run.placement != null ? (
From 175679c68cdd5450630709a7bd8465a81fdcca96 Mon Sep 17 00:00:00 2001
From: zasbu <136494048+zasbu@users.noreply.github.com>
Date: Sat, 7 Nov 2026 00:46:44 +1100
Subject: [PATCH 06/12] Turn the activity page into one board with paged runs
and quieter filter menus
---
web/src/app/activity/page.tsx | 31 +-
web/src/features/activity/RecentRunTable.tsx | 329 ++++++++++--------
web/src/features/activity/RecentRuns.tsx | 105 +++---
web/src/features/dailyTotals/DailyTotals.tsx | 14 +-
.../features/dailyTotals/DailyTotalsChart.tsx | 159 +++++----
web/src/features/replays/ReplayLink.tsx | 2 +-
web/src/ui/ChoiceMenu.tsx | 7 +-
web/src/ui/Menu.tsx | 7 +-
web/src/ui/Table.tsx | 12 +-
9 files changed, 389 insertions(+), 277 deletions(-)
diff --git a/web/src/app/activity/page.tsx b/web/src/app/activity/page.tsx
index 769fcfa..c142c7a 100644
--- a/web/src/app/activity/page.tsx
+++ b/web/src/app/activity/page.tsx
@@ -1,5 +1,5 @@
-// Activity page: runs and world records per day, then the latest runs, narrowed by style, track, lowest tier or
-// world records only.
+// Activity page: one board. Runs and world records per day, then the latest runs, narrowed by style, track,
+// lowest tier or world records only.
import type { Metadata } from "next";
import { RecentRuns } from "@/features/activity/RecentRuns";
import { DailyTotals } from "@/features/dailyTotals/DailyTotals";
@@ -12,19 +12,20 @@ export const metadata: Metadata = {
export default function ActivityPage({ searchParams }: PageProps<"/activity">) {
return (
-
-
);
}
diff --git a/web/src/features/activity/RecentRunTable.tsx b/web/src/features/activity/RecentRunTable.tsx
index 08aa761..f33c207 100644
--- a/web/src/features/activity/RecentRunTable.tsx
+++ b/web/src/features/activity/RecentRunTable.tsx
@@ -1,7 +1,8 @@
"use client";
-// The latest runs as a table: who, which board, the time, and where it placed when it finished. "Show more"
-// loads older runs a page at a time.
-import { useState, type CSSProperties } from "react";
+// The latest runs as a table: who, which board, the time, and where it placed when it finished. Previous and
+// Next step through older runs a page at a time.
+import { ChevronLeft, ChevronRight } from "lucide-react";
+import { useRef, useState, type CSSProperties } from "react";
import { api, type Schemas } from "@/api/client";
import { ReplayLink } from "@/features/replays/ReplayLink";
import { RunLink } from "@/features/runs/RunLink";
@@ -14,7 +15,6 @@ import {
import { Avatar } from "@/ui/Avatar";
import { Badge } from "@/ui/Badge";
import { Button } from "@/ui/Button";
-import { Card } from "@/ui/Card";
import { classNames } from "@/ui/classNames";
import { Flag } from "@/ui/Flag";
import { Link } from "@/ui/Link";
@@ -35,6 +35,7 @@ type Query = {
track?: "main" | "bonus";
min_tier?: number;
records?: boolean;
+ limit?: number;
};
export function RecentRunTable({
@@ -50,17 +51,36 @@ export function RecentRunTable({
/** With every style shown, each run names its own. */
showStyle: boolean;
}) {
- const [runs, setRuns] = useState(first.runs);
- const [cursor, setCursor] = useState(first.next_cursor);
+ // Pages already seen stay loaded, so going back is instant.
+ const [pages, setPages] = useState([first]);
+ const [index, setIndex] = useState(0);
const [loading, setLoading] = useState(false);
const [failed, setFailed] = useState(false);
+ const board = useRef(null);
+ const rows = useRef(null);
+ // Held at the first page's height, so a short last page doesn't pull the page controls up.
+ const [minHeight, setMinHeight] = useState();
const tierCount = first.tier_count;
+ const page = pages[index] ?? first;
+ const runs = page.runs;
- async function showMore(after: string) {
+ function show(next: number) {
+ setMinHeight((held) => held ?? rows.current?.offsetHeight);
+ setIndex(next);
+ // Keep the table's top in view when a page is turned from the bottom of a long page.
+ const top = board.current?.getBoundingClientRect().top ?? 0;
+ if (top < 0) board.current?.scrollIntoView({ block: "start" });
+ }
+
+ async function showNext() {
+ if (pages[index + 1]) return show(index + 1);
+ if (!page.next_cursor) return;
setLoading(true);
setFailed(false);
const loaded = await api
- .GET("/v1/runs", { params: { query: { ...query, cursor: after } } })
+ .GET("/v1/runs", {
+ params: { query: { ...query, cursor: page.next_cursor } },
+ })
.then((result) => result.data)
.catch(() => undefined);
setLoading(false);
@@ -68,158 +88,181 @@ export function RecentRunTable({
setFailed(true);
return;
}
- setRuns((shown) => [...shown, ...loaded.runs]);
- setCursor(loaded.next_cursor);
+ setPages((seen) => [...seen.slice(0, index + 1), loaded]);
+ show(index + 1);
}
if (runs.length === 0) {
return (
-
+
{query.records
? "No world records match these choices."
: "No runs match these choices."}
-
+
);
}
return (
-
-
-
-
- Player
- Map
-
- Time
-
- {/* Narrow padding keeps the play button close to the time and the place. */}
-
- Replay
-
-
- Place
-
-
;
+ return {frame};
}
function Stat({
diff --git a/web/src/features/replays/ReplayLink.tsx b/web/src/features/replays/ReplayLink.tsx
index 6bfa728..1bc3db2 100644
--- a/web/src/features/replays/ReplayLink.tsx
+++ b/web/src/features/replays/ReplayLink.tsx
@@ -25,7 +25,7 @@ export function ReplayLink({ runId }: { runId: number }) {
onClick={onClick}
aria-label="Watch replay"
title="Watch replay"
- className="text-text-muted hover:bg-accent-soft hover:text-accent inline-flex size-6 shrink-0 items-center justify-center rounded-md transition-colors duration-(--duration-fast)"
+ className="text-text-muted hover:text-accent inline-flex size-6 shrink-0 items-center justify-center rounded-md transition-colors duration-(--duration-fast)"
>
diff --git a/web/src/ui/ChoiceMenu.tsx b/web/src/ui/ChoiceMenu.tsx
index bb683eb..287a71d 100644
--- a/web/src/ui/ChoiceMenu.tsx
+++ b/web/src/ui/ChoiceMenu.tsx
@@ -43,12 +43,15 @@ export function ChoiceMenu({
<>
{label}{chosen?.label ?? value}
-
+
>
}
// On a phone each menu takes a full row, label on the left and value on the right, so menus of different
// widths line up as one column instead of wrapping unevenly.
- triggerClassName="border-border bg-surface hover:bg-surface-raised flex h-9 w-full items-center gap-2 rounded-md border px-3 text-sm whitespace-nowrap transition-colors duration-(--duration-fast) sm:inline-flex sm:w-auto"
+ triggerClassName="group bg-text/4 hover:bg-text/8 aria-expanded:bg-text/8 flex h-8 w-full items-center gap-1.5 rounded-md px-2.5 text-sm whitespace-nowrap transition-colors duration-(--duration-fast) sm:inline-flex sm:w-auto"
>
{options.map((option) => {
const className = classNames(
diff --git a/web/src/ui/Menu.tsx b/web/src/ui/Menu.tsx
index 7fe8813..81be014 100644
--- a/web/src/ui/Menu.tsx
+++ b/web/src/ui/Menu.tsx
@@ -95,7 +95,7 @@ export function Menu({
}}
// A long list (the Maps page's sorts) scrolls inside the menu rather than running off a short screen.
className={classNames(
- "border-border-strong bg-surface-overlay text-text shadow-popover motion-pop m-0 mt-2 max-h-[min(28rem,70vh)] min-w-48 overflow-y-auto overscroll-contain rounded-md border p-1 text-sm",
+ "border-border-strong bg-surface-overlay text-text shadow-popover motion-pop m-0 mt-1 max-h-[min(28rem,70vh)] min-w-44 overflow-y-auto overscroll-contain rounded-lg border p-1 text-sm",
matchTriggerWidth && "max-sm:min-w-[anchor-size(width)]",
)}
>
@@ -105,8 +105,9 @@ export function Menu({
);
}
+// The overlay is lighter than surface-raised, so hover lifts with a tint of the text color instead.
const itemClasses =
- "flex h-9 w-full items-center gap-2 rounded-sm px-3 text-left outline-none hover:bg-surface-raised focus-visible:bg-surface-raised [&_svg]:size-4 [&_svg]:text-text-muted";
+ "flex h-8 w-full items-center gap-2 rounded-md px-2.5 text-left outline-none transition-colors duration-(--duration-fast) hover:bg-text/8 focus-visible:bg-text/8 [&_svg]:size-4 [&_svg]:text-text-muted aria-checked:[&_svg]:text-accent";
export function MenuItem({ className, ...props }: ComponentProps<"button">) {
return (
@@ -132,5 +133,5 @@ export function MenuLink({ className, ...props }: ComponentProps) {
}
export function MenuSeparator() {
- return ;
+ return ;
}
diff --git a/web/src/ui/Table.tsx b/web/src/ui/Table.tsx
index 0c219b4..47d0e9a 100644
--- a/web/src/ui/Table.tsx
+++ b/web/src/ui/Table.tsx
@@ -2,14 +2,22 @@
import type { ComponentProps } from "react";
import { classNames } from "./classNames";
-export function Table({ className, ...props }: ComponentProps<"table">) {
+export function Table({
+ flush = false,
+ className,
+ ...props
+}: {
+ /** No frame of its own. The parent supplies the surface, as on the activity board. */
+ flush?: boolean;
+} & ComponentProps<"table">) {
return (
// Wide tables scroll sideways on small screens instead of squeezing their columns. `relative` keeps
// absolutely placed content, such as a visually hidden column name, inside the scrolling box. Never
// vertically: rows rising into place (`motion-enter`) overflow for a moment, which flashed a scrollbar.
From 447179a76ef76687ad80c4332e62874f3f7da7c8 Mon Sep 17 00:00:00 2001
From: zasbu <136494048+zasbu@users.noreply.github.com>
Date: Sat, 7 Nov 2026 00:55:57 +1100
Subject: [PATCH 07/12] Page activity runs from a hundred at a time, with page
numbers in the address and ok-style filters
---
web/src/app/activity/page.tsx | 3 +-
web/src/features/activity/RecentRunTable.tsx | 209 ++++++++++++-------
web/src/features/activity/RecentRuns.tsx | 92 ++++++--
web/src/ui/ChoiceMenu.tsx | 9 +-
web/src/ui/Menu.tsx | 5 +
web/src/ui/Pager.tsx | 154 ++++++++++++--
6 files changed, 354 insertions(+), 118 deletions(-)
diff --git a/web/src/app/activity/page.tsx b/web/src/app/activity/page.tsx
index c142c7a..df4720b 100644
--- a/web/src/app/activity/page.tsx
+++ b/web/src/app/activity/page.tsx
@@ -15,13 +15,14 @@ export default function ActivityPage({ searchParams }: PageProps<"/activity">) {
- {searchParams.then(({ style, track, tier, show }) => (
+ {searchParams.then(({ style, track, tier, show, page }) => (
))}
diff --git a/web/src/features/activity/RecentRunTable.tsx b/web/src/features/activity/RecentRunTable.tsx
index f33c207..e760d42 100644
--- a/web/src/features/activity/RecentRunTable.tsx
+++ b/web/src/features/activity/RecentRunTable.tsx
@@ -1,8 +1,16 @@
"use client";
-// The latest runs as a table: who, which board, the time, and where it placed when it finished. Previous and
-// Next step through older runs a page at a time.
-import { ChevronLeft, ChevronRight } from "lucide-react";
-import { useRef, useState, type CSSProperties } from "react";
+// The latest runs as a table: who, which board, the time, and where it placed when it finished. Runs come a
+// hundred at a time and are paged here, so turning a page is instant; the next hundred load in the background.
+import { useSearchParams } from "next/navigation";
+import {
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+ type CSSProperties,
+ type FormEvent,
+ type MouseEvent,
+} from "react";
import { api, type Schemas } from "@/api/client";
import { ReplayLink } from "@/features/replays/ReplayLink";
import { RunLink } from "@/features/runs/RunLink";
@@ -14,11 +22,11 @@ import {
} from "@/features/runs/time";
import { Avatar } from "@/ui/Avatar";
import { Badge } from "@/ui/Badge";
-import { Button } from "@/ui/Button";
import { classNames } from "@/ui/classNames";
import { Flag } from "@/ui/Flag";
import { Link } from "@/ui/Link";
import { Medal } from "@/ui/Medal";
+import { Pager } from "@/ui/Pager";
import {
Table,
TableBody,
@@ -29,7 +37,7 @@ import {
} from "@/ui/Table";
import { TierBadge } from "@/ui/TierBadge";
-type Page = Schemas["RecentRuns"];
+type Runs = Schemas["RecentRuns"];
type Query = {
style?: string;
track?: "main" | "bonus";
@@ -41,55 +49,124 @@ type Query = {
export function RecentRunTable({
first,
query,
+ address,
+ page: firstPage,
+ pageSize,
styleNames,
showStyle,
}: {
- first: Page;
- /** The filters `first` was loaded with, for loading the pages after it. */
+ /** The newest runs, enough to reach `page`. */
+ first: Runs;
+ /** The filters `first` was loaded with, for loading the runs after it. */
query: Query;
+ /** The page's address with these filters, which the page number is added to. */
+ address: string;
+ page: number;
+ pageSize: number;
styleNames: Record;
/** With every style shown, each run names its own. */
showStyle: boolean;
}) {
- // Pages already seen stay loaded, so going back is instant.
- const [pages, setPages] = useState([first]);
- const [index, setIndex] = useState(0);
- const [loading, setLoading] = useState(false);
+ const [runs, setRuns] = useState(first.runs);
+ const [cursor, setCursor] = useState(first.next_cursor ?? null);
const [failed, setFailed] = useState(false);
+ const [waiting, setWaiting] = useState(false);
+ // The latest runs and cursor for the loops below, which outlive the render that started them.
+ const latest = useRef({
+ runs: first.runs,
+ cursor: first.next_cursor ?? null,
+ });
+ const inFlight = useRef | null>(null);
const board = useRef(null);
const rows = useRef(null);
// Held at the first page's height, so a short last page doesn't pull the page controls up.
const [minHeight, setMinHeight] = useState();
const tierCount = first.tier_count;
- const page = pages[index] ?? first;
- const runs = page.runs;
- function show(next: number) {
+ // The address holds the page, so a reload, a shared link and the back button all land on it.
+ const asked = Number(useSearchParams().get("page") ?? firstPage);
+ const pageCount = Math.max(1, Math.ceil(runs.length / pageSize));
+ const page = Math.min(Math.max(1, Math.floor(asked) || 1), pageCount);
+ const shown = runs.slice((page - 1) * pageSize, page * pageSize);
+
+ const pageHref = useCallback(
+ (p: number) =>
+ p > 1
+ ? `${address}${address.includes("?") ? "&" : "?"}page=${p}`
+ : address,
+ [address],
+ );
+
+ /** Loads the next hundred runs, once however many ask; false when there are none or they failed. */
+ const loadMore = useCallback((): Promise => {
+ if (inFlight.current) return inFlight.current;
+ const after = latest.current.cursor;
+ if (!after) return Promise.resolve(false);
+ inFlight.current = api
+ .GET("/v1/runs", { params: { query: { ...query, cursor: after } } })
+ .then((result) => result.data)
+ .catch(() => undefined)
+ .then((next) => {
+ inFlight.current = null;
+ setFailed(!next);
+ if (!next) return false;
+ latest.current = {
+ runs: [...latest.current.runs, ...next.runs],
+ cursor: next.next_cursor ?? null,
+ };
+ setRuns(latest.current.runs);
+ setCursor(latest.current.cursor);
+ return true;
+ });
+ return inFlight.current;
+ }, [query]);
+
+ // Keeps a few pages loaded past the one shown, so Next never waits.
+ useEffect(() => {
+ if (cursor && !failed && runs.length < (page + 4) * pageSize)
+ void loadMore();
+ }, [cursor, failed, runs.length, page, pageSize, loadMore]);
+
+ async function go(target: number) {
+ // A typed page past what's loaded walks forward to it, or to the last page if the runs end first.
+ while (latest.current.runs.length < target * pageSize) {
+ setWaiting(true);
+ if (!(await loadMore())) break;
+ }
+ setWaiting(false);
+ const count = Math.max(1, Math.ceil(latest.current.runs.length / pageSize));
setMinHeight((held) => held ?? rows.current?.offsetHeight);
- setIndex(next);
+ window.history.pushState(null, "", pageHref(Math.min(target, count)));
// Keep the table's top in view when a page is turned from the bottom of a long page.
const top = board.current?.getBoundingClientRect().top ?? 0;
if (top < 0) board.current?.scrollIntoView({ block: "start" });
}
- async function showNext() {
- if (pages[index + 1]) return show(index + 1);
- if (!page.next_cursor) return;
- setLoading(true);
- setFailed(false);
- const loaded = await api
- .GET("/v1/runs", {
- params: { query: { ...query, cursor: page.next_cursor } },
- })
- .then((result) => result.data)
- .catch(() => undefined);
- setLoading(false);
- if (!loaded) {
- setFailed(true);
+ // The pager's links and box work without this; here they turn the page without asking the server.
+ function onPagerClick(event: MouseEvent) {
+ const link = (event.target as HTMLElement).closest("a");
+ if (
+ !link ||
+ event.button !== 0 ||
+ event.metaKey ||
+ event.ctrlKey ||
+ event.shiftKey ||
+ event.altKey
+ )
return;
- }
- setPages((seen) => [...seen.slice(0, index + 1), loaded]);
- show(index + 1);
+ // Stopped here too, as Next's Link and Form navigate even when the event is already prevented.
+ event.preventDefault();
+ event.stopPropagation();
+ void go(Number(new URL(link.href).searchParams.get("page") ?? 1));
+ }
+
+ function onPagerSubmit(event: FormEvent) {
+ event.preventDefault();
+ event.stopPropagation();
+ const form = event.target as HTMLFormElement;
+ const typed = Math.floor(Number(new FormData(form).get("page")));
+ form.reset();
+ if (typed >= 1) void go(typed);
}
if (runs.length === 0) {
@@ -104,7 +181,15 @@ export function RecentRunTable({
return (
-
+
@@ -123,8 +208,8 @@ export function RecentRunTable({
{/* Keyed by page, so a turned page's rows fade in like the first. */}
-
- {runs.map((run, row) => (
+
+ {shown.map((run, row) => (
- {(index > 0 || page.next_cursor) && (
-
);
diff --git a/web/src/features/activity/RecentRuns.tsx b/web/src/features/activity/RecentRuns.tsx
index e9c7a0d..8173c96 100644
--- a/web/src/features/activity/RecentRuns.tsx
+++ b/web/src/features/activity/RecentRuns.tsx
@@ -1,5 +1,5 @@
// The Activity page's runs: the filter menus, read from and written to the address, and the first page of runs.
-import { api } from "@/api/client";
+import { api, type Schemas } from "@/api/client";
import { currentStyles } from "@/features/ruleset/styles";
import { ChoiceBar } from "@/ui/ChoiceBar";
import { ChoiceMenu } from "@/ui/ChoiceMenu";
@@ -19,8 +19,22 @@ export interface RecentRunsParams {
tier?: string;
/** "records": world records only. */
show?: string;
+ page?: string;
}
+const PAGE_SIZE = 15;
+/** Runs per request. A hundred cost the API about what fifteen do, so most pages turn without a request. */
+const CHUNK = 100;
+/** How far a typed page number may walk before giving up, at one request per hundred runs. */
+const MAX_CHUNKS = 20;
+
+type RunsQuery = {
+ style?: string;
+ track?: "main" | "bonus";
+ min_tier?: number;
+ records?: boolean;
+};
+
interface Filters {
style?: string;
track: Track;
@@ -29,24 +43,30 @@ interface Filters {
}
export async function RecentRuns({ params }: { params: RecentRunsParams }) {
- const styles = await currentStyles();
- const filters: Filters = {
- style: styles.keys.find((key) => key === params.style),
- track: tracks.find((t) => t.key === params.track)?.key ?? "all",
- tier: Math.floor(Number(params.tier)) || undefined,
- records: params.show === "records",
- };
- const query = {
- style: filters.style,
- track: filters.track === "all" ? undefined : filters.track,
- min_tier: filters.tier,
- records: filters.records || undefined,
- limit: 15,
- };
- const result = await api
- .GET("/v1/runs", { params: { query } })
- .catch(() => undefined);
- const first = result?.data;
+ const track = tracks.find((t) => t.key === params.track)?.key ?? "all";
+ const tier = Math.floor(Number(params.tier)) || undefined;
+ const records = params.show === "records";
+ const page = Math.max(1, Math.floor(Number(params.page)) || 1);
+ const queryFor = (style: string | undefined): RunsQuery => ({
+ style,
+ track: track === "all" ? undefined : track,
+ min_tier: tier,
+ records: records || undefined,
+ });
+
+ // The runs don't wait for the ruleset: the style in the address is almost always one it ranks, and only a
+ // stale one costs a second request.
+ const [styles, guessed] = await Promise.all([
+ currentStyles(),
+ loadRuns(queryFor(params.style || undefined), page),
+ ]);
+ const style = styles.keys.find((key) => key === params.style);
+ const query = queryFor(style);
+ const first =
+ style === (params.style || undefined)
+ ? guessed
+ : await loadRuns(query, page);
+ const filters: Filters = { style, track, tier, records };
const tierCount = first?.tier_count ?? undefined;
// Only what differs from the defaults goes in the address, so the plain page stays /activity.
@@ -131,7 +151,10 @@ export async function RecentRuns({ params }: { params: RecentRunsParams }) {
[key, styles.name(key)]),
)}
@@ -141,3 +164,32 @@ export async function RecentRuns({ params }: { params: RecentRunsParams }) {
);
}
+
+/** Runs from the newest, enough to reach `page`; undefined when the first request fails. */
+async function loadRuns(
+ query: RunsQuery,
+ page: number,
+): Promise {
+ const get = (cursor?: string) =>
+ api
+ .GET("/v1/runs", {
+ params: { query: { ...query, limit: CHUNK, cursor } },
+ })
+ .then((result) => result.data)
+ .catch(() => undefined);
+ const first = await get();
+ if (!first) return undefined;
+ const runs = [...first.runs];
+ let cursor = first.next_cursor;
+ for (
+ let chunk = 1;
+ cursor && runs.length < page * PAGE_SIZE && chunk < MAX_CHUNKS;
+ chunk++
+ ) {
+ const next = await get(cursor);
+ if (!next) break;
+ runs.push(...next.runs);
+ cursor = next.next_cursor;
+ }
+ return { ...first, runs, next_cursor: cursor };
+}
diff --git a/web/src/ui/ChoiceMenu.tsx b/web/src/ui/ChoiceMenu.tsx
index 287a71d..936fcd9 100644
--- a/web/src/ui/ChoiceMenu.tsx
+++ b/web/src/ui/ChoiceMenu.tsx
@@ -45,17 +45,20 @@ export function ChoiceMenu({
{chosen?.label ?? value}
>
}
// On a phone each menu takes a full row, label on the left and value on the right, so menus of different
// widths line up as one column instead of wrapping unevenly.
- triggerClassName="group bg-text/4 hover:bg-text/8 aria-expanded:bg-text/8 flex h-8 w-full items-center gap-1.5 rounded-md px-2.5 text-sm whitespace-nowrap transition-colors duration-(--duration-fast) sm:inline-flex sm:w-auto"
+ // Darker than the surface it sits on, like a well, so it reads as a control without competing with the data.
+ triggerClassName="group border-border bg-bg hover:border-border-strong hover:bg-surface-raised aria-expanded:border-border-strong aria-expanded:bg-surface-raised flex h-9 w-full items-center gap-2 rounded-md border pr-2.5 pl-3 text-sm font-medium whitespace-nowrap transition-colors duration-(--duration-fast) sm:inline-flex sm:w-auto"
>
{options.map((option) => {
const className = classNames(
- (option.quiet || option.disabled) && "text-text-subtle",
+ option.quiet || option.disabled
+ ? "text-text-subtle"
+ : "text-text-muted hover:text-text aria-checked:text-accent",
option.disabled && "cursor-not-allowed",
);
const content = (
diff --git a/web/src/ui/Menu.tsx b/web/src/ui/Menu.tsx
index 81be014..2af025d 100644
--- a/web/src/ui/Menu.tsx
+++ b/web/src/ui/Menu.tsx
@@ -7,6 +7,7 @@ import {
type ToggleEvent,
useId,
useRef,
+ useState,
} from "react";
import { Link } from "./Link";
import { anchoredStyle, anchorStyle } from "./anchor";
@@ -35,6 +36,8 @@ export function Menu({
}) {
const id = useId();
const menu = useRef(null);
+ // Mirrored onto the trigger, so its open look can follow the popover.
+ const [open, setOpen] = useState(false);
const items = () =>
Array.from(
menu.current?.querySelectorAll(
@@ -43,6 +46,7 @@ export function Menu({
);
function onToggle(event: ToggleEvent) {
+ setOpen(event.newState === "open");
if (event.newState === "open") items()[0]?.focus();
}
@@ -67,6 +71,7 @@ export function Menu({
type="button"
popoverTarget={id}
aria-haspopup="menu"
+ aria-expanded={open}
aria-label={label}
style={anchorStyle(id)}
className={triggerClassName}
diff --git a/web/src/ui/Pager.tsx b/web/src/ui/Pager.tsx
index e1cd260..37cf00e 100644
--- a/web/src/ui/Pager.tsx
+++ b/web/src/ui/Pager.tsx
@@ -1,39 +1,147 @@
-// Previous and next links under a paged list, with where the reader is.
+// Page links under a paged list: both ends, the current page and its neighbours, and a box for going straight to
+// a page.
import { ChevronLeft, ChevronRight } from "lucide-react";
-import { ButtonLink } from "./Button";
+import Form from "next/form";
+import type { ReactNode } from "react";
+import { classNames } from "./classNames";
+import { Link } from "./Link";
-/** Renders nothing when everything fits on one page. Pages count from 1. */
+const PARAM = "page";
+
+const cell =
+ "inline-flex h-8 min-w-8 items-center justify-center rounded-md px-2 text-sm tabular-nums transition-colors duration-(--duration-fast)";
+const link = "text-text-muted hover:bg-text/8 hover:text-text";
+
+/**
+ * Renders nothing when everything fits on one page. Pages count from 1 and sit in the address as `?page=`, so
+ * `href(1)` also gives the address the box keeps. A list whose length isn't known yet passes the pages loaded so
+ * far and `more`, and its last page shows as a gap.
+ */
export function Pager({
page,
pageCount,
+ more = false,
href,
}: {
page: number;
pageCount: number;
+ more?: boolean;
href: (page: number) => string;
}) {
- if (pageCount <= 1) return null;
+ if (pageCount <= 1 && !more) return null;
+ const last = more ? pageCount + 1 : pageCount;
+ const shown = [
+ ...new Set([1, page - 1, page, page + 1, ...(more ? [] : [pageCount])]),
+ ]
+ .filter((p) => p >= 1 && p <= last)
+ .sort((a, b) => a - b);
+ const base = new URL(href(1), "http://site");
+ base.searchParams.delete(PARAM);
+
+ const items = [];
+ let previous = 0;
+ for (const p of shown) {
+ if (p - previous > 1) items.push();
+ items.push(
+
+ {p}
+ ,
+ );
+ previous = p;
+ }
+ if (more) items.push();
+
return (
-