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

@ -176,6 +176,7 @@ also in `admin-schema.js` and a CHECK):
| Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` |
| Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` |
| Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping |
| Front page → Countdown → Only this type | retreat, class, workshop, meeting, other | **yes** | `server/src/routes/home.js` (picks the countdown event). The same values as Events → Type, so adding a type widens both CHECKs. |
| Front page → Background | brand, photos | **yes** | `HeroStage.tsx` |
| Front page → Feature | none, livestream, video | **yes** | `HeroStage.tsx` |
| Front page → Sections → Section | countdown, retreats, calendar, stats, timeline, connect | **yes**, `FRONT_PAGE_SECTIONS` | `SECTIONS` in `src/pages/Home.tsx`; see [below](#front-page-section-names) |
@ -191,7 +192,7 @@ code):
| Dropdown | `optionsFrom` | Comes from |
| --- | --- | --- |
| Chapter → Region | `regions` | organizations of kind region |
| Event → Scope (+ list filter) | `event_scopes` | the `event_scopes` table (migration only) |
| Event → Scope (+ list filter); Front page → Countdown → Only this scope | `event_scopes` | the `event_scopes` table (migration only) |
| Event hosts → Organization; affiliations; team and award "Organization" / "Awarded by"; person → Home organization | `organizations` | organizations, labelled by name |
| Event hosts / event people / team members / timeline people → Person | `people` | people |
| Affiliations → Team | `teams` | teams, filtered to the chosen organization |

View file

@ -691,6 +691,8 @@ const frontPage = {
text("video_url"),
text("video_title"),
text("countdown_event_id"),
text("countdown_scope_id"),
enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]),
],
children: [

View file

@ -0,0 +1,29 @@
-- ═══════════════════════════════════════════════════════════════
-- 026 COUNTDOWN: FILTER BY SCOPE AND TYPE
--
-- The countdown counts to the pinned event, or else to the next
-- published event that hasn't ended. These two narrow "the next
-- event": National + Retreat counts down to the next national
-- retreat and skips a regional class that happens sooner. Either or
-- both can be left null, meaning any. A pinned event still wins
-- whatever they say; the admin chose it by name.
--
-- countdown_scope_id an event_scopes id. A real foreign key,
-- so it can't name a scope that doesn't
-- exist; ON DELETE SET NULL puts it back to
-- "any" if a scope is ever removed.
-- countdown_event_type the same values as events.event_type.
-- Adding an event type now means widening
-- this CHECK too.
--
-- Plain ADD COLUMN: a REFERENCES column is allowed when its default
-- is NULL, and a CHECK is allowed on any. No rebuild.
--
-- PRAGMA user_version; -- reads 25 before this file
-- ═══════════════════════════════════════════════════════════════
ALTER TABLE front_page ADD COLUMN countdown_scope_id TEXT
REFERENCES event_scopes (id) ON DELETE SET NULL;
ALTER TABLE front_page ADD COLUMN countdown_event_type TEXT
CHECK (countdown_event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other'));

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: {

View file

@ -1066,6 +1066,28 @@ const frontPage = {
blankLabel: "Default: the next upcoming event",
help: "Leave blank almost always. A pinned event that's over falls back to the next one",
},
{
path: "countdown_scope_id",
label: "Only this scope",
widget: "select",
optionsFrom: "event_scopes",
blankLabel: "Default: any scope",
help: "Narrows the next upcoming event. Ignored when an event is pinned above",
},
{
path: "countdown_event_type",
label: "Only this type",
widget: "select",
options: [
["retreat", "Retreat"],
["class", "Class"],
["workshop", "Workshop"],
["meeting", "Meeting"],
["other", "Other"],
],
blankLabel: "Default: any type",
help: "Combines with the scope: National + Retreat counts down to the next national retreat",
},
],
},
],

View file

@ -2,18 +2,20 @@
EVENT TYPES
The client half of the CHECK on events.event_type. Order here is
display order — the filter chips read it straight off this array,
display order: the filter chips read it straight off this array,
so moving a line moves a chip.
What this is not: event_scopes. A scope owns presentation —
What this is not: event_scopes. A scope owns presentation:
Retreats.tsx keys its title, accent and background on the id, so
an unrecognised scope_id makes an event vanish with no error,
which is why that one is a real table with a real foreign key. A
type carries no presentation of its own and an unknown value
renders as its own name, so a CHECK is enough.
Adding a type is three edits: the CHECK in a migration, the enum
in both descriptor halves, and this list. Adding it here alone
Adding a type is three edits: the CHECKs in a migration (on
events.event_type and front_page.countdown_event_type), the enums
in both descriptor halves (the event's type and the front page's
countdown type), and this list. Adding it here alone
means the site offers a filter the database will refuse to store.
═══════════════════════════════════════════════════════════════ */
@ -37,7 +39,7 @@ const capitalize = (word: string) =>
word ? word.charAt(0).toUpperCase() + word.slice(1) : ''
/* A value the CHECK has gained since this file was written renders
as itself rather than vanishing — the same rule EventDetail's
as itself rather than vanishing, the same rule EventDetail's
ROLE_ORDER follows for billing roles. */
export const eventTypeLabel = (id?: string | null): string =>
(id ? BY_ID.get(id)?.label : null) ?? capitalize(id ?? '')