Let the front page countdown filter by event scope and type

Admin > Front page > Countdown gains two optional dropdowns, "Only
this scope" and "Only this type", each defaulting to any. They narrow
which event counts as "the next one": National + Retreat counts down
to the next national retreat and skips a sooner regional class. A
pinned event still wins over both. When nothing matches, the
countdown band doesn't render, as before.

Migration 026 adds front_page.countdown_scope_id, a foreign key to
event_scopes (ON DELETE SET NULL, so removing a scope returns it to
"any"), and countdown_event_type, checked against the same values as
events.event_type. Adding an event type now widens both CHECKs; the
note in eventTypes.ts and the guide say so.

Also clears the older em-dashes from home.js and eventTypes.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-26 19:59:29 -05:00
parent 54bf649b8d
commit 68f08b633c
6 changed files with 83 additions and 11 deletions

View file

@ -1,5 +1,5 @@
/* ═══════════════════════════════════════════════════════════════
FRONT PAGE ROUTE — read-only, mounted under /api
FRONT PAGE ROUTE: read-only, mounted under /api
GET /front-page the home page's configuration, resolved
@ -26,6 +26,11 @@
ended. "Hasn't ended" is COALESCE(ends_on, starts_on) >= today,
so a running series with a start date in the past still counts.
The client works out the next meeting of a series from `series`.
countdown_scope_id and countdown_event_type narrow "the next
event" (National + Retreat skips a sooner regional class). Null
means any. They don't apply to a pinned event: the admin chose
that one by name.
═══════════════════════════════════════════════════════════════ */
import { Hono } from "hono";
@ -57,7 +62,7 @@ const STAT_QUERIES = {
WHERE pa.is_public = 1`,
};
/* The number as a string, or null when there's nothing to print —
/* The number as a string, or null when there's nothing to print:
a manual stat nobody filled in, or a year that isn't one. */
function statValue(db, row) {
if (row.source === "manual") return row.value || null;
@ -145,16 +150,27 @@ home.get("/front-page", (c) => {
.get(page.countdown_event_id)
: null;
const filters = [];
const params = [];
if (page.countdown_scope_id) {
filters.push("AND scope_id = ?");
params.push(page.countdown_scope_id);
}
if (page.countdown_event_type) {
filters.push("AND event_type = ?");
params.push(page.countdown_event_type);
}
const next =
pinned ??
db
.prepare(
`SELECT * FROM v_events
WHERE ${notOver}
WHERE ${notOver} ${filters.join(" ")}
ORDER BY starts_on, title
LIMIT 1`,
)
.get();
.get(...params);
return json(c, {
front_page: {