From f934b1dd936d0954c213d3df8b057a510f21cd38 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Tue, 29 Sep 2026 03:02:21 -0500 Subject: [PATCH] Tidy the structure the audit found - The colour defaults have one source, server/src/themeDefaults.js, read by the server and the admin; the build stops if src/index.css disagrees with it - server/src/admin-schema.js split into admin-schema/, one file per entity plus columns.js (the registry checked identical) - loadOwned() in shape.js replaces the same three loads on four detail routes (every public route checked identical); one NO_STORE - One OrgLogo component for the org lists and the chapter map; an organization's own page now shows the same initials as the lists - One localISO() for the viewer's calendar day, in place of three - Boot refuses a descriptor dropdown value the table's CHECK doesn't allow, instead of it failing on save - Deleted the unused Other.tsx and white-background logo; chapters.ts is useCommunity.ts; isSuper() in the Panel; stale comments and docs corrected Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 4 +- docs/updating-data-in-code.md | 17 +- server/src/admin-schema-sync.js | 22 + server/src/admin-schema.js | 943 +---------------------- server/src/admin-schema/awards.js | 36 + server/src/admin-schema/blog.js | 92 +++ server/src/admin-schema/columns.js | 202 +++++ server/src/admin-schema/events.js | 113 +++ server/src/admin-schema/frontPage.js | 126 +++ server/src/admin-schema/organizations.js | 86 +++ server/src/admin-schema/people.js | 99 +++ server/src/admin-schema/siteSettings.js | 58 ++ server/src/admin-schema/teams.js | 66 ++ server/src/admin-schema/timeline.js | 63 ++ server/src/routes/admin-entities.js | 2 +- server/src/routes/admin.js | 2 +- server/src/routes/auth.js | 2 +- server/src/routes/clips.js | 2 +- server/src/routes/content.js | 13 +- server/src/routes/media.js | 2 +- server/src/routes/pages.js | 4 +- server/src/routes/panel.js | 2 +- server/src/routes/people.js | 6 +- server/src/shape.js | 13 + server/src/theme.js | 23 +- server/src/themeDefaults.js | 29 + src/assets/logos/NGU_Logo_WhiteBG.svg | 82 -- src/components/OrgLogo.tsx | 39 + src/data/feedbackTypes.ts | 5 +- src/lib/adminSchema/siteSettings.ts | 41 +- src/lib/eventSeries.ts | 8 +- src/lib/hrefs.ts | 2 +- src/lib/organizations.ts | 5 +- src/lib/timeline.ts | 9 +- src/lib/{chapters.ts => useCommunity.ts} | 13 +- src/lib/useContent.ts | 4 +- src/lib/useRecord.ts | 4 +- src/pages/OrganizationDetail.tsx | 5 +- src/pages/Other.tsx | 13 - src/pages/admin/AdminPanel.tsx | 6 +- src/pages/sections/EventCalendar.tsx | 4 +- src/pages/sections/OrgList-Card.tsx | 24 +- src/pages/sections/OrgList-Map.tsx | 27 +- vite.config.ts | 39 + 44 files changed, 1187 insertions(+), 1170 deletions(-) create mode 100644 server/src/admin-schema/awards.js create mode 100644 server/src/admin-schema/blog.js create mode 100644 server/src/admin-schema/columns.js create mode 100644 server/src/admin-schema/events.js create mode 100644 server/src/admin-schema/frontPage.js create mode 100644 server/src/admin-schema/organizations.js create mode 100644 server/src/admin-schema/people.js create mode 100644 server/src/admin-schema/siteSettings.js create mode 100644 server/src/admin-schema/teams.js create mode 100644 server/src/admin-schema/timeline.js create mode 100644 server/src/themeDefaults.js delete mode 100644 src/assets/logos/NGU_Logo_WhiteBG.svg create mode 100644 src/components/OrgLogo.tsx rename src/lib/{chapters.ts => useCommunity.ts} (92%) delete mode 100644 src/pages/Other.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 3382282..c6a1596 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -67,14 +67,14 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - **Imports need explicit extensions** (`.ts`, `.tsx`, `.js`) everywhere. - **Vite resolves `.js` before `.ts`**, so a `.js` and `.ts` file with the same base name will import the wrong one. Give new hooks distinct names. - **Don't use `fallback: EMPTY` in api.ts hooks.** It silently returns empty arrays and hides server errors; let the error state surface. -- **Colours are tokens, not hex.** Admins can override any token (Panel → Site settings → Colours); the defaults live in three places that must agree: `src/index.css`, `THEME_DEFAULTS` in `server/src/theme.js`, `THEME_COLORS` in `src/lib/adminSchema/siteSettings.ts`. Use the utilities from `src/index.css` (`text-ink`, `text-body`, `text-muted`, `text-link`, `bg-surface`, `bg-tint`, `bg-action`, `border-brand/20`...) so dark mode works; a literal only for something that must look the same in both modes (white on a dark band, a platform's colour). Data colours (accents, event and region colours) go through `withAlpha`, `accentText` and `readableOn` in `src/lib/color.ts`, never `${color}55`. +- **Colours are tokens, not hex.** Admins can override any token (Panel → Site settings → Colours). The defaults are `server/src/themeDefaults.js` plus the same values as CSS in `src/index.css`; the build fails if they differ (`themeDefaultsCheck` in `vite.config.ts`), and migration 041's CHECK lists the token names. Use the utilities from `src/index.css` (`text-ink`, `text-body`, `text-muted`, `text-link`, `bg-surface`, `bg-tint`, `bg-action`, `border-brand/20`...) so dark mode works; a literal only for something that must look the same in both modes (white on a dark band, a platform's colour). Data colours (accents, event and region colours) go through `withAlpha`, `accentText` and `readableOn` in `src/lib/color.ts`, never `${color}55`. - **Icons are Phosphor** (`@phosphor-icons/react`), weight `bold` (or `fill` for play/star). No hand-drawn `` icons and no Unicode glyphs as icons (× › ▶ →). Brand marks are the exception: `DoveMark`, `PlatformIcon`, the Google logo, the chapter map. - **Accents come from `src/lib/color.ts`:** `BRAND` (the teal, via the button token so the admin palette reaches it) and `ACCENTS` (deep, green, mint). Not a new hex in a page. - **No em-dashes** (U+2014) anywhere: UI text, help text, comments, docs, commit messages. Use a colon, comma or parentheses. An empty table cell shows `-`. - **Admin editor text:** blank select options read `Default: …` (what blank means), examples in help text start with `eg.`, and record ids are called "URL ID". Cut-off preview text uses `preview()` from `src/lib/text.ts`, which ends it with an ellipsis. See `docs/updating-data-in-code.md`. ## Admin CRUD engine -Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema.js` (server) and `src/lib/adminSchema/` (client, one file per entity, registered in `adminSchema.ts`) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code. +Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema/` (server, one file per entity, registered in `admin-schema.js`) and `src/lib/adminSchema/` (client, one file per entity, registered in `adminSchema.ts`) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code. - Child collections are deleted and reinserted wholesale. Unsafe for entities referenced by foreign keys elsewhere. - `reindex: false` prevents cross-entity sort order collisions. - `check: (db, id) => void` runs after a save has written everything, inside its transaction; throwing an `HttpError` refuses the save (Site settings uses it for the colour contrast check, `server/src/theme.js`). diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index 7e3baac..715cb90 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -50,7 +50,7 @@ each entity: | File | What it holds | | ----------------------------- | ----------------------------------------------------- | | `src/lib/adminSchema/` (one file per entity, `shared.ts` for common fields; `src/lib/adminSchema.ts` lists them) | The **form**: field labels, help text, dropdown labels, list columns and filters | -| `server/src/admin-schema.js` | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` | +| `server/src/admin-schema/` (one file per entity, `columns.js` for shared helpers; `server/src/admin-schema.js` lists them) | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` | And the database itself holds the final word: most fixed lists are a `CHECK (... IN (...))` constraint on the column (read them in @@ -145,7 +145,7 @@ together, in one branch: **Renaming** a value also needs an `UPDATE` in the same migration so existing rows move to the new value. **Removing** one needs you to decide what existing rows become first. -2. **`server/src/admin-schema.js`**: the `enumeration("column", [...])` +2. **`server/src/admin-schema/.js`**: the `enumeration("column", [...])` list for that column. 3. **`src/lib/adminSchema/.ts`**: the `options` on the form field, and on the list filter if there is one. @@ -161,11 +161,11 @@ wrong rather than working around it. ### Every dropdown in the editor **Fixed lists** (`options`: labels in `src/lib/adminSchema/`, values -also in `admin-schema.js` and a CHECK): +also in `server/src/admin-schema/` and a CHECK): | Entity → field | Stored values | Labelled? | Also used on the public site by | | --- | --- | --- | --- | -| Organizations → Kind (+ list filter) | national, region, chapter, partner | no, shows values | `ORG_KIND_LABEL` in `src/lib/hrefs.ts`, and the route each kind uses | +| Organizations → Kind (+ list filter) | national, region, chapter, partner | no, shows values | `ORG_BASE` in `src/lib/hrefs.ts` (the route each kind uses) and `orgListHref` there (its back link) | | Organizations → Region → Scope | domestic, international, virtual | no | the Community page groups regions by it | | Organizations → Region areas → Edge | top, bottom | no | the chapter map (`OrgList-Map.tsx`) | | Events → Type (+ list filter) | retreat, class, workshop, meeting, other | no | `EVENT_TYPES` in `src/lib/eventTypes.ts` (public labels and plurals) | @@ -206,7 +206,6 @@ code): | Affiliations → Team | `teams` | teams, filtered to the chosen organization | | Person awards → Award | `awards` | awards, labelled "Award (Organization)" | | Person awards → Presented at; Front page → Count down to; Front page → Featured event | `events` | events | -| Timeline → Record | `timeline_refs` | all five kinds, filtered by "Points at" | --- @@ -243,7 +242,7 @@ change the band's `id`. **Adding a new kind of band** (not just renaming one) is a feature, not a relabel: it needs a component, an entry in `SECTIONS` in `Home.tsx`, the key added to `FRONT_PAGE_SECTIONS`, to the -`enumeration("section", …)` in `server/src/admin-schema.js`, to the +`enumeration("section", …)` in `server/src/admin-schema/frontPage.js`, to the `FrontPageSectionKey` type in `src/lib/useFrontPage.ts`, and to the CHECK on `front_page_sections.section` via a migration. @@ -259,7 +258,7 @@ The numbers band's "Number Source" dropdown works the same way: matching public page shows (published rows), or the number and the page will disagree. - **Add a source:** the CHECK on `front_page_stats.source` (migration), - the `enumeration("source", …)` in `server/src/admin-schema.js`, + the `enumeration("source", …)` in `server/src/admin-schema/frontPage.js`, `STAT_SOURCES`, and a query in `STAT_QUERIES`. --- @@ -274,13 +273,13 @@ The numbers band's "Number Source" dropdown works the same way: | History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. | | Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). | | Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. | -| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are the `@theme` tokens and dark block in `src/index.css`, and must stay the same in `THEME_DEFAULTS` (`server/src/theme.js`) and `THEME_COLORS` (`src/lib/adminSchema/siteSettings.ts`). Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. | +| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. | | The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. | | A page section's accent colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. | | Privacy Policy and Terms wording | `src/pages/Privacy.tsx`, `src/pages/Terms.tsx` | The `PARTS` list, and `LAST_UPDATED` whenever the wording changes. The Privacy page must stay true of the code: what the feedback form stores, what the browser keeps, which embeds wait for a click. | | Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. | | Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | | -| Organization kind labels ("Region", "Chapter") | `ORG_KIND_LABEL` in `src/lib/hrefs.ts` | | +| Organization kind labels ("Region", "Chapter") | the Kind options in `src/lib/adminSchema/organizations.ts` (admin); `orgListHref` in `src/lib/hrefs.ts` (the public back link, "All regions") | | | Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. | | Admin navigation | `src/pages/admin/adminNav.ts` | | | The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | | diff --git a/server/src/admin-schema-sync.js b/server/src/admin-schema-sync.js index 3dd7c6a..5c671d0 100644 --- a/server/src/admin-schema-sync.js +++ b/server/src/admin-schema-sync.js @@ -22,6 +22,15 @@ than waiting to surface one row at a time. ═══════════════════════════════════════════════════════════════ */ +/* The values a CHECK (column IN (...)) on the table allows, read from + its CREATE TABLE, or null when there's no such CHECK. */ +function checkValues(db, table, column) { + const sql = db.prepare(`SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = ?`).get(table)?.sql ?? ""; + const match = new RegExp(`\\b${column}"?\\s+IN\\s*\\(([^)]*)\\)`, "i").exec(sql); + if (!match) return null; + return new Set([...match[1].matchAll(/'((?:[^']|'')*)'/g)].map((m) => m[1].replace(/''/g, "'"))); +} + function tableMeta(db, table) { const rows = db.prepare(`PRAGMA table_info(${table})`).all(); if (!rows.length) return null; @@ -114,6 +123,19 @@ export function syncDescriptorsWithSchema(db, entities) { inferred.push(`${name}: ${group.table}.${column.name}`); } if (info.notNullable) column.notNullable = true; + + // A dropdown value the table's CHECK refuses would only fail + // when someone saves it; say so at boot instead. + if (column.type === "enum") { + const allowed = checkValues(db, group.table, column.name); + const refused = allowed ? column.values.filter((value) => !allowed.has(value)) : []; + if (refused.length) { + problems.push( + `${name}: ${group.table}.${column.name} offers ${refused.join(", ")}, ` + + `which the table's CHECK doesn't allow.`, + ); + } + } } for (const [columnName, info] of meta) { diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index 69cc8dd..7c62f6b 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -1,6 +1,10 @@ /* ═══════════════════════════════════════════════════════════════ ADMIN ENTITY DESCRIPTORS + One object per editable entity, one file each in admin-schema/ + (the shared column helpers and child collections are in + admin-schema/columns.js); this file lists them. + One object per editable entity. Everything the CRUD handlers do (validation, SQL, nesting) is read from here, so adding a table later is a descriptor rather than another set of @@ -38,936 +42,15 @@ what the other side owns rather than blanking it. ═══════════════════════════════════════════════════════════════ */ -import { THEME_TOKENS, checkTheme } from "./theme.js"; - -/* ── Column helpers ──────────────────────────────────────────── */ - -const text = (name, opts = {}) => ({ name, type: "text", ...opts }); -// Text that is a link: refuses javascript:, data: and other schemes. -const url = (name, opts = {}) => ({ name, type: "url", ...opts }); -const int = (name, opts = {}) => ({ name, type: "int", ...opts }); -const real = (name, opts = {}) => ({ name, type: "real", ...opts }); -const bool = (name, opts = {}) => ({ name, type: "bool", ...opts }); -const date = (name, opts = {}) => ({ name, type: "date", ...opts }); -const time = (name, opts = {}) => ({ name, type: "time", ...opts }); -const enumeration = (name, values, opts = {}) => ({ - name, - type: "enum", - values, - ...opts, -}); - -/* Place columns shared by organizations and events, in schema order. */ -const placeColumns = [ - text("venue"), - text("address"), - text("locality"), - text("state_code"), - text("country"), - text("location_label"), - real("latitude"), - real("longitude"), - bool("is_online"), -]; - -/* The affiliation's own fields, minus whichever end owns the row. - Both editors write the same shape so neither loses the other's - values on save. */ -const affiliationRole = [ - text("title"), - enumeration("role", ["lead", "board", "staff", "volunteer", "member"], { - required: true, - }), - bool("is_owner"), - date("started_on"), - date("ended_on"), - bool("is_public"), -]; - -/* The editable half of a timeline entry, shared by the standalone - editor and by the in_timeline extension on events and organizations. - - occurred_on is text, not date. "2012" and "2025-07" are legitimate - values (a backfilled entry often knows the year and nothing more), - and the date coercion would reject both. `precision` is what says how - much of it to believe. */ -const timelineFields = [ - text("occurred_on"), - enumeration("precision", ["year", "month", "day"]), - text("title"), - text("blurb"), - text("meta"), - url("link_url"), - bool("is_featured"), - bool("is_published"), - int("sort_order"), -]; - -/* The extension that the in_timeline checkbox drives. Ticked, the row - is upserted; unticked, writeExtensions deletes it. Both happen in the - parent's transaction, so the flag and the row cannot disagree. - - The conflict target is the UNIQUE (ref_kind, ref_id) constraint - on timeline_entries, which is also what stops a second save creating a - duplicate instead of updating the first. */ -const timelineExtension = (refKind) => ({ - key: "timeline", - table: "timeline_entries", - owner: { column: "ref_id", kindColumn: "ref_kind", kindValue: refKind }, - conflict: ["ref_kind", "ref_id"], - when: { column: "in_timeline", value: 1 }, - columns: [ - // Fixed for this end: an event's entry is always an event entry. - // Declared as a default rather than a form field so the column is - // written without asking. - enumeration( - "kind", - ["milestone", "event", "organization", "award", "people"], - { default: refKind === "organization" ? "organization" : refKind }, - ), - ...timelineFields, - ], -}); - -/* Featured cards (030_featured_cards.sql): polymorphic like links, - so the Community blog can own a set too. */ -const featuredCardsChild = (ownerKind) => ({ - key: "featured_cards", - table: "featured_cards", - owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, - order: "sort_order", - columns: [ - enumeration("kind", ["record", "link", "video"], { required: true }), - enumeration("ref_kind", ["event", "organization", "person", "team", "award"]), - text("ref_id"), - url("url"), - text("eyebrow"), - text("title"), - text("blurb"), - text("image"), - ], -}); - -/* The two polymorphic collections, parameterised by owner_kind. */ -const linksChild = (ownerKind) => ({ - key: "links", - table: "links", - owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, - order: "sort_order", - columns: [ - enumeration("kind", ["action", "social", "website", "email"], { - required: true, - }), - text("platform"), - text("label", { required: true }), - url("url", { required: true }), - bool("is_primary"), - ], -}); - -const blocksChild = (ownerKind) => ({ - key: "content_blocks", - table: "content_blocks", - owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, - order: "sort_order", - columns: [ - enumeration("slot", ["card", "body"], { required: true }), - enumeration( - "type", - [ - "heading", - "subheading", - "paragraph", - "list", - "links", - "quote", - "image", - "divider", - "video", - "button", - "callout", - "schedule", - ], - { required: true }, - ), - text("text"), - text("media"), - url("href"), - text("alt"), - text("cite"), - ], - children: [ - { - key: "items", - table: "content_block_items", - owner: { column: "block_id" }, - order: "sort_order", - columns: [ - text("text", { required: true }), - text("detail"), - url("url"), - // Schedule entries only (034_schedule_block.sql). - text("day"), - text("time"), - text("location"), - text("person_id"), - text("description"), - text("media"), - text("media_alt"), - text("map"), - ], - }, - ], -}); - -/* Hosts. One row is one host, ordered, each either an organization - or a person. The CHECK on event_hosts rejects both and the blank - filter drops neither, so the only bad row that reaches SQLite is - one with both selects filled, and that comes back keyed to the - row like any other field error. - - Not parameterised the way links and blocks are: this table is - events-only, and the owner column says so. - - sort_order isn't declared. The engine writes it from the row's - position because `order` is "sort_order", which is what makes - the first row the one v_events takes the logo and colour from. */ -const hostsChild = { - key: "event_hosts", - table: "event_hosts", - owner: { column: "event_id" }, - order: "sort_order", - columns: [text("org_id"), text("person_id")], -}; - -/* ── Organizations ───────────────────────────────────────────── */ - -const organizations = { - key: "organizations", - table: "organizations", - idColumn: "id", - idKind: "slug", - concurrency: "updated_at", - - list: { - columns: [ - "id", - "kind", - "name", - "short_name", - "locality", - "state_code", - "is_published", - "is_listed", - "sort_order", - "updated_at", - ], - filters: ["kind", "is_published", "is_listed"], - search: ["name", "id", "locality"], - order: "kind, sort_order, name", - }, - - columns: [ - enumeration("kind", ["national", "region", "chapter", "partner"], { - required: true, - }), - text("name", { required: true }), - text("short_name"), - text("tagline"), - text("color"), - text("logo"), - ...placeColumns, - bool("is_published"), - bool("is_listed"), - int("sort_order"), - bool("in_timeline"), - ], - - extensions: [ - timelineExtension("organization"), - { - key: "region", - table: "regions", - idColumn: "id", - when: { column: "kind", value: "region" }, - columns: [ - enumeration("scope", ["domestic", "international", "virtual"], { - required: true, - }), - text("map_note"), - ], - }, - { - key: "chapter", - table: "chapters", - idColumn: "id", - when: { column: "kind", value: "chapter" }, - columns: [text("region_id"), text("meets"), text("started")], - }, - ], - - children: [ - linksChild("organization"), - blocksChild("organization"), - { - key: "region_areas", - table: "region_areas", - owner: { column: "region_id" }, - when: { column: "kind", value: "region" }, - order: "area_code", - columns: [ - text("area_code", { required: true }), - real("share"), - enumeration("edge", ["top", "bottom"]), - text("note"), - ], - }, - ], -}; - -/* ── Events ──────────────────────────────────────────────────── */ - -/* Column suffixes for the series weekday flags, Sunday first to - match Date#getDay. */ -const SERIES_WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; - -const events = { - key: "events", - table: "events", - idColumn: "id", - idKind: "slug", - concurrency: "updated_at", - - list: { - columns: [ - "id", - "title", - "scope_id", - "event_type", - "date_label", - "starts_on", - "status", - "is_published", - "is_listed", - "updated_at", - ], - // No host filter: hosts are rows in another table now, and the - // engine's filters are columns on this one. The events a host - // owns are on that host's own page. - filters: ["scope_id", "event_type", "status", "is_published", "is_listed"], - search: ["title", "id", "theme"], - order: "starts_on IS NULL, starts_on DESC, title", - }, - - columns: [ - text("scope_id", { required: true }), - - // What kind of gathering, as against scope_id's whose gathering - // it is. Declared required even though the column has a - // DEFAULT: every select renders a blank first option, so without - // it a new event files itself as a retreat while nobody is - // looking. An existing row always loads with its value set, so - // this only ever asks on create. - enumeration( - "event_type", - ["retreat", "class", "workshop", "meeting", "other"], - { required: true }, - ), - - text("title", { required: true }), - text("theme"), - text("tagline"), - date("starts_on"), - date("ends_on"), - text("date_label"), - enumeration("status", ["upcoming", "past", "cancelled"]), - ...placeColumns, - text("org_logo"), - text("event_logo"), - text("color"), - text("card_image"), - bool("is_published"), - bool("is_listed"), - bool("in_timeline"), - - // A repeating schedule. Columns rather than a side table: the - // schedule is always exactly one per event, and the public view - // is SELECT e.*, so it reaches the site with no join. Ignored - // while is_series is 0. The events table in the schema says - // what each means. - bool("is_series"), - enumeration("series_frequency", ["weekly", "monthly_date", "monthly_weekday"]), - int("series_interval"), - ...SERIES_WEEKDAYS.map((day) => bool(`series_${day}`)), - time("series_start_time"), - time("series_end_time"), - int("series_count"), - ], - - extensions: [timelineExtension("event")], - - children: [ - hostsChild, - linksChild("event"), - blocksChild("event"), - { - key: "event_people", - table: "event_people", - owner: { column: "event_id" }, - order: "sort_order", - columns: [ - text("person_id", { required: true }), - enumeration( - "role", - [ - "speaker", - "leader", - "facilitator", - "host", - "musician", - "volunteer", - "attendee", - ], - { required: true }, - ), - text("title"), - bool("is_public"), - ], - }, - ], -}; - -/* ── People ──────────────────────────────────────────────────── */ - -const people = { - key: "people", - table: "people", - idColumn: "id", - idKind: "slug", - concurrency: "updated_at", - - list: { - columns: [ - "id", - "display_name", - "sort_name", - "tagline", - "locality", - "is_published", - "is_listed", - "updated_at", - ], - filters: ["is_published", "is_listed"], - search: ["display_name", "sort_name", "id"], - order: "sort_name, display_name", - }, - - columns: [ - text("display_name", { required: true }), - text("sort_name"), - text("pronouns"), - text("tagline"), - text("photo"), - text("bio"), - text("primary_org_id"), - text("public_email"), - text("public_phone"), - text("locality"), - text("state_code"), - text("country"), - text("location_label"), - bool("is_published"), - bool("is_listed"), - ], - - extensions: [ - { - key: "private", - table: "person_private", - idColumn: "person_id", - readRole: "editor", // viewers don't see birth dates, addresses, phones - touch: true, // has its own updated_at with no trigger behind it - columns: [ - date("birth_date"), - text("private_email"), - text("private_phone"), - text("address"), - text("notes"), - ], - }, - ], - - children: [ - linksChild("person"), - blocksChild("person"), - { - key: "affiliations", - table: "affiliations", - owner: { column: "person_id" }, - - // sort_order is where this person sits on that team, so it - // belongs to the team's editor. reindex: false stops this - // form renumbering by row position; declaring the column - // keeps the team's value intact across a save here. - reindex: false, - order: "org_id, team_id, sort_order", - - columns: [ - text("org_id", { required: true }), - text("team_id"), - ...affiliationRole, - int("sort_order"), - ], - }, - { - key: "person_awards", - table: "person_awards", - owner: { column: "person_id" }, - order: "awarded_on", - columns: [ - text("award_id", { required: true }), - text("event_id"), - date("awarded_on"), - text("citation"), - bool("is_public"), - ], - }, - ], -}; - -/* ── Teams ───────────────────────────────────────────────────── */ - -// A team belongs to exactly one organization, and affiliations -// point at the pair (team_id, org_id) rather than the team alone. -// Two consequences the form has to live with: -// -// · org_id cannot be changed once anyone is filed under the -// team. The composite foreign key has no ON UPDATE CASCADE, so -// SQLite aborts the UPDATE. That surfaces as a constraint -// error, which is the correct answer: reassign the members -// first. -// -// · deleting a team with members fails the same way, rather than -// quietly detaching them. Emptying the members list first is -// now something the form can do. -const teams = { - key: "teams", - table: "teams", - idColumn: "id", - idKind: "slug", - concurrency: "updated_at", - - list: { - columns: ["id", "org_id", "name", "tagline", "is_published", "is_listed", "sort_order", "updated_at"], - filters: ["org_id", "is_published", "is_listed"], - search: ["name", "id", "tagline"], - order: "org_id, sort_order, name", - }, - - columns: [ - text("org_id", { required: true }), - text("name", { required: true }), - text("tagline"), - text("color"), - text("logo"), - bool("is_published"), - bool("is_listed"), - int("sort_order"), - ], - - children: [ - // 'team' is already a valid owner_kind in both polymorphic - // tables, and teams_cleanup drops the rows on delete, so a team - // page comes free. - linksChild("team"), - blocksChild("team"), - { - key: "members", - table: "affiliations", - - // org_id is inherited from the team rather than asked for: - // the composite foreign key (team_id, org_id) means a member - // of this team can only belong to this team's organization, - // so a second dropdown could only ever be wrong. - owner: { column: "team_id", inherit: { org_id: "org_id" } }, - - // Row position is the order they appear on the public site. - // This is the only editor that writes it. - order: "sort_order", - - columns: [text("person_id", { required: true }), ...affiliationRole], - }, - ], -}; - -/* ── Awards ──────────────────────────────────────────────────── */ - -// org_id is who gives the award. Nullable, because -// an award can predate any decision about which organization owns -// it, and because person_awards rows must survive the awarding -// org being deleted. -// -// No children: 'award' is not in the owner_kind CHECK on -// content_blocks or links. If awards ever need a page of their -// own, that CHECK is a table rebuild, so decide before adding one -// rather than after. -const awards = { - key: "awards", - table: "awards", - idColumn: "id", - idKind: "slug", - - list: { - columns: ["id", "org_id", "name", "description", "is_published", "is_listed", "sort_order"], - filters: ["org_id", "is_published", "is_listed"], - search: ["name", "id", "description"], - order: "org_id, sort_order, name", - }, - - columns: [ - text("org_id"), - text("name", { required: true }), - text("description"), - text("logo"), - bool("is_published"), - bool("is_listed"), - int("sort_order"), - ], -}; - -/* ── Timeline ────────────────────────────────────────────────── */ - -// The history page's spine, and the only entity whose id the table -// assigns. There is nothing to slug: an entry referencing an event has -// no name of its own, and one gets created every time somebody ticks a -// checkbox. idKind "auto" is what lets createRow skip the id entirely. -// -// ref_kind and ref_id are writable here and only here. The extension on -// events and organizations owns those two columns for rows it created, -// which is why they aren't in timelineFields. -// -// Deleting an entry takes its people with it (ON DELETE CASCADE) and -// nothing points at an entry, so the delete-and-reinsert child engine -// is safe on this one. -const timeline = { - key: "timeline", - table: "timeline_entries", - idColumn: "id", - idKind: "auto", - concurrency: "updated_at", - - list: { - columns: [ - "id", - "kind", - "ref_kind", - "ref_id", - "occurred_on", - "title", - "is_featured", - "is_published", - "updated_at", - ], - filters: ["kind", "ref_kind", "is_featured", "is_published"], - search: ["title", "blurb", "meta", "ref_id"], - // Undated entries sort last rather than first, so a missing date - // reads as something to fix instead of something to scroll past. - order: "occurred_on IS NULL, occurred_on DESC, sort_order", - }, - - columns: [ - enumeration( - "kind", - ["milestone", "event", "organization", "award", "people"], - { required: true }, - ), - enumeration("ref_kind", ["event", "organization", "award", "person", "team"]), - text("ref_id"), - ...timelineFields, - ], - - children: [ - { - key: "people", - table: "timeline_entry_people", - owner: { column: "entry_id" }, - order: "sort_order", - columns: [text("person_id", { required: true }), text("note")], - }, - ], -}; - -/* ── Front page ────────────────────────────────────────────────── - - A singleton: one row, id 'home', seeded by the schema and never - created by the admin. `singleton` tells the engine to refuse create - and delete, and the CHECK on front_page.id is what makes a second - row impossible even without it. - - Every collection here is owned by page_id and replaced wholesale. - That is safe for the same reason it is for links and blocks - (nothing has a foreign key into these tables), and paths carry - their actions as a nested collection, the shape content blocks - and their items already use. */ - -const frontPage = { - key: "front_page", - table: "front_page", - idColumn: "id", - idKind: "slug", - singleton: "home", - concurrency: "updated_at", - - list: { - columns: ["id", "headline", "hero_backdrop", "hero_feature", "updated_at"], - filters: [], - search: [], - order: "id", - }, - - columns: [ - enumeration("hero_backdrop", ["brand", "photos"]), - enumeration("hero_feature", ["none", "livestream", "video", "event"]), - text("hero_event_id"), - text("eyebrow"), - text("headline"), - text("subhead"), - text("primary_label"), - url("primary_url"), - text("secondary_label"), - url("secondary_url"), - int("slide_seconds"), - url("livestream_url"), - text("livestream_title"), - url("video_url"), - text("video_title"), - text("countdown_event_id"), - text("countdown_scope_id"), - enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]), - ], - - children: [ - { - key: "slides", - table: "front_page_slides", - owner: { column: "page_id" }, - order: "sort_order", - columns: [ - text("media", { required: true }), - text("alt"), - text("caption"), - url("link_url"), - ], - }, - { - key: "sections", - table: "front_page_sections", - owner: { column: "page_id" }, - order: "sort_order", - columns: [ - enumeration( - "section", - ["countdown", "retreats", "calendar", "stats", "timeline", "connect", "featured"], - { required: true }, - ), - text("title"), - text("blurb"), - bool("is_hidden"), - ], - }, - { - key: "stats", - table: "front_page_stats", - owner: { column: "page_id" }, - order: "sort_order", - columns: [ - text("label", { required: true }), - enumeration("source", [ - "manual", - "years_since", - "regions", - "chapters", - "partners", - "events_held", - "retreats_held", - "people", - "awards_given", - ]), - text("value"), - text("suffix"), - text("note"), - ], - }, - featuredCardsChild("front_page"), - { - key: "paths", - table: "front_page_paths", - owner: { column: "page_id" }, - order: "sort_order", - columns: [text("label", { required: true }), text("icon"), text("blurb")], - children: [ - { - key: "actions", - table: "front_page_path_actions", - owner: { column: "path_id" }, - order: "sort_order", - columns: [ - text("label", { required: true }), - text("description"), - url("url", { required: true }), - ], - }, - ], - }, - ], -}; - -/* ── Blog (031_blog.sql) ───────────────────────────────────────── - - Posts of our own, with a content-block body and people as - authors, and the Community page's blog section, a singleton like - the front page. The section's community posts are featured cards - owned by 'community_page'. ─────────────────────────────────── */ - -const blogPosts = { - key: "blog_posts", - table: "blog_posts", - idColumn: "id", - idKind: "slug", - concurrency: "updated_at", - - list: { - columns: ["id", "title", "published_on", "tags", "is_published", "is_listed", "updated_at"], - filters: ["is_published", "is_listed"], - search: ["title", "id", "tags"], - order: "published_on IS NULL, published_on DESC, title", - }, - - columns: [ - text("title", { required: true }), - text("excerpt"), - text("cover_image"), - text("cover_alt"), - date("published_on"), - text("tags"), - text("guest_author"), - text("guest_photo"), - bool("is_published"), - bool("is_listed"), - ], - - children: [ - { - key: "authors", - table: "blog_post_authors", - owner: { column: "post_id" }, - order: "sort_order", - columns: [text("person_id", { required: true })], - }, - blocksChild("blog_post"), - ], -}; - -const communityPage = { - key: "community_page", - table: "community_page", - idColumn: "id", - idKind: "slug", - singleton: "community", - concurrency: "updated_at", - - list: { - columns: ["id", "blog_title", "updated_at"], - filters: [], - search: [], - order: "id", - }, - - columns: [ - text("blog_title"), - text("blog_blurb"), - text("internal_title"), - int("internal_slots"), - text("external_title"), - int("external_slots"), - url("external_url"), - text("external_label"), - ], - - children: [ - { - key: "pinned_posts", - table: "community_page_pinned_posts", - owner: { column: "page_id" }, - order: "sort_order", - columns: [text("post_id", { required: true })], - }, - featuredCardsChild("community_page"), - { - key: "feeds", - table: "community_page_feeds", - owner: { column: "page_id" }, - order: "sort_order", - columns: [url("url", { required: true }), text("label")], - }, - ], -}; - -/* ── Site settings (035_site_settings.sql) ────────────────────── - A singleton of overrides for what site.json says: name, - description, preview image, icons, search indexing, and static - pages' titles and intros. Superadmins only. pageMeta.js merges it - over site.json. */ -const siteSettings = { - key: "site_settings", - table: "site_settings", - idColumn: "id", - idKind: "slug", - singleton: "site", - concurrency: "updated_at", - writeRole: "superadmin", - - list: { - columns: ["id", "site_name", "updated_at"], - filters: [], - search: [], - order: "id", - }, - - columns: [ - text("site_name"), - text("description"), - text("preview_image"), - text("favicon"), - text("apple_touch_icon"), - enumeration("indexing", ["on", "off"]), - text("privacy_email"), - ], - - children: [ - { - key: "pages", - table: "site_setting_pages", - owner: { column: "settings_id" }, - order: "sort_order", - columns: [text("path", { required: true }), text("title"), text("description")], - }, - { - key: "colors", - table: "site_setting_colors", - owner: { column: "settings_id" }, - order: "sort_order", - columns: [ - enumeration("token", THEME_TOKENS, { required: true }), - text("light"), - text("dark"), - ], - }, - ], - - // Refuses a palette that would make text hard to read (theme.js). - check: checkTheme, -}; +import { organizations } from "./admin-schema/organizations.js"; +import { events } from "./admin-schema/events.js"; +import { people } from "./admin-schema/people.js"; +import { teams } from "./admin-schema/teams.js"; +import { awards } from "./admin-schema/awards.js"; +import { timeline } from "./admin-schema/timeline.js"; +import { frontPage } from "./admin-schema/frontPage.js"; +import { blogPosts, communityPage } from "./admin-schema/blog.js"; +import { siteSettings } from "./admin-schema/siteSettings.js"; export const ENTITIES = { organizations, diff --git a/server/src/admin-schema/awards.js b/server/src/admin-schema/awards.js new file mode 100644 index 0000000..1643124 --- /dev/null +++ b/server/src/admin-schema/awards.js @@ -0,0 +1,36 @@ +import { text, int, bool } from "./columns.js"; + +/* ── Awards ──────────────────────────────────────────────────── */ + +// org_id is who gives the award. Nullable, because +// an award can predate any decision about which organization owns +// it, and because person_awards rows must survive the awarding +// org being deleted. +// +// No children: 'award' is not in the owner_kind CHECK on +// content_blocks or links. If awards ever need a page of their +// own, that CHECK is a table rebuild, so decide before adding one +// rather than after. +export const awards = { + key: "awards", + table: "awards", + idColumn: "id", + idKind: "slug", + + list: { + columns: ["id", "org_id", "name", "description", "is_published", "is_listed", "sort_order"], + filters: ["org_id", "is_published", "is_listed"], + search: ["name", "id", "description"], + order: "org_id, sort_order, name", + }, + + columns: [ + text("org_id"), + text("name", { required: true }), + text("description"), + text("logo"), + bool("is_published"), + bool("is_listed"), + int("sort_order"), + ], +}; diff --git a/server/src/admin-schema/blog.js b/server/src/admin-schema/blog.js new file mode 100644 index 0000000..bece207 --- /dev/null +++ b/server/src/admin-schema/blog.js @@ -0,0 +1,92 @@ +import { text, url, int, bool, date, featuredCardsChild, blocksChild } from "./columns.js"; + +/* ── Blog (031_blog.sql) ───────────────────────────────────────── + + Posts of our own, with a content-block body and people as + authors, and the Community page's blog section, a singleton like + the front page. The section's community posts are featured cards + owned by 'community_page'. ─────────────────────────────────── */ + +export const blogPosts = { + key: "blog_posts", + table: "blog_posts", + idColumn: "id", + idKind: "slug", + concurrency: "updated_at", + + list: { + columns: ["id", "title", "published_on", "tags", "is_published", "is_listed", "updated_at"], + filters: ["is_published", "is_listed"], + search: ["title", "id", "tags"], + order: "published_on IS NULL, published_on DESC, title", + }, + + columns: [ + text("title", { required: true }), + text("excerpt"), + text("cover_image"), + text("cover_alt"), + date("published_on"), + text("tags"), + text("guest_author"), + text("guest_photo"), + bool("is_published"), + bool("is_listed"), + ], + + children: [ + { + key: "authors", + table: "blog_post_authors", + owner: { column: "post_id" }, + order: "sort_order", + columns: [text("person_id", { required: true })], + }, + blocksChild("blog_post"), + ], +}; + +export const communityPage = { + key: "community_page", + table: "community_page", + idColumn: "id", + idKind: "slug", + singleton: "community", + concurrency: "updated_at", + + list: { + columns: ["id", "blog_title", "updated_at"], + filters: [], + search: [], + order: "id", + }, + + columns: [ + text("blog_title"), + text("blog_blurb"), + text("internal_title"), + int("internal_slots"), + text("external_title"), + int("external_slots"), + url("external_url"), + text("external_label"), + ], + + children: [ + { + key: "pinned_posts", + table: "community_page_pinned_posts", + owner: { column: "page_id" }, + order: "sort_order", + columns: [text("post_id", { required: true })], + }, + featuredCardsChild("community_page"), + { + key: "feeds", + table: "community_page_feeds", + owner: { column: "page_id" }, + order: "sort_order", + columns: [url("url", { required: true }), text("label")], + }, + ], +}; diff --git a/server/src/admin-schema/columns.js b/server/src/admin-schema/columns.js new file mode 100644 index 0000000..311dd4c --- /dev/null +++ b/server/src/admin-schema/columns.js @@ -0,0 +1,202 @@ +/* Column helpers, and the field sets and child collections several + entities share. The descriptor anatomy is in ../admin-schema.js. */ + +/* ── Column helpers ──────────────────────────────────────────── */ + +export const text = (name, opts = {}) => ({ name, type: "text", ...opts }); +// Text that is a link: refuses javascript:, data: and other schemes. +export const url = (name, opts = {}) => ({ name, type: "url", ...opts }); +export const int = (name, opts = {}) => ({ name, type: "int", ...opts }); +export const real = (name, opts = {}) => ({ name, type: "real", ...opts }); +export const bool = (name, opts = {}) => ({ name, type: "bool", ...opts }); +export const date = (name, opts = {}) => ({ name, type: "date", ...opts }); +export const time = (name, opts = {}) => ({ name, type: "time", ...opts }); +export const enumeration = (name, values, opts = {}) => ({ + name, + type: "enum", + values, + ...opts, +}); + +/* Place columns shared by organizations and events, in schema order. */ +export const placeColumns = [ + text("venue"), + text("address"), + text("locality"), + text("state_code"), + text("country"), + text("location_label"), + real("latitude"), + real("longitude"), + bool("is_online"), +]; + +/* The affiliation's own fields, minus whichever end owns the row. + Both editors write the same shape so neither loses the other's + values on save. */ +export const affiliationRole = [ + text("title"), + enumeration("role", ["lead", "board", "staff", "volunteer", "member"], { + required: true, + }), + bool("is_owner"), + date("started_on"), + date("ended_on"), + bool("is_public"), +]; + +/* The editable half of a timeline entry, shared by the standalone + editor and by the in_timeline extension on events and organizations. + + occurred_on is text, not date. "2012" and "2025-07" are legitimate + values (a backfilled entry often knows the year and nothing more), + and the date coercion would reject both. `precision` is what says how + much of it to believe. */ +export const timelineFields = [ + text("occurred_on"), + enumeration("precision", ["year", "month", "day"]), + text("title"), + text("blurb"), + text("meta"), + url("link_url"), + bool("is_featured"), + bool("is_published"), + int("sort_order"), +]; + +/* The extension that the in_timeline checkbox drives. Ticked, the row + is upserted; unticked, writeExtensions deletes it. Both happen in the + parent's transaction, so the flag and the row cannot disagree. + + The conflict target is the UNIQUE (ref_kind, ref_id) constraint + on timeline_entries, which is also what stops a second save creating a + duplicate instead of updating the first. */ +export const timelineExtension = (refKind) => ({ + key: "timeline", + table: "timeline_entries", + owner: { column: "ref_id", kindColumn: "ref_kind", kindValue: refKind }, + conflict: ["ref_kind", "ref_id"], + when: { column: "in_timeline", value: 1 }, + columns: [ + // Fixed for this end: an event's entry is always an event entry. + // Declared as a default rather than a form field so the column is + // written without asking. + enumeration( + "kind", + ["milestone", "event", "organization", "award", "people"], + { default: refKind === "organization" ? "organization" : refKind }, + ), + ...timelineFields, + ], +}); + +/* Featured cards (030_featured_cards.sql): polymorphic like links, + so the Community blog can own a set too. */ +export const featuredCardsChild = (ownerKind) => ({ + key: "featured_cards", + table: "featured_cards", + owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, + order: "sort_order", + columns: [ + enumeration("kind", ["record", "link", "video"], { required: true }), + enumeration("ref_kind", ["event", "organization", "person", "team", "award"]), + text("ref_id"), + url("url"), + text("eyebrow"), + text("title"), + text("blurb"), + text("image"), + ], +}); + +/* The two polymorphic collections, parameterised by owner_kind. */ +export const linksChild = (ownerKind) => ({ + key: "links", + table: "links", + owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, + order: "sort_order", + columns: [ + enumeration("kind", ["action", "social", "website", "email"], { + required: true, + }), + text("platform"), + text("label", { required: true }), + url("url", { required: true }), + bool("is_primary"), + ], +}); + +export const blocksChild = (ownerKind) => ({ + key: "content_blocks", + table: "content_blocks", + owner: { column: "owner_id", kindColumn: "owner_kind", kindValue: ownerKind }, + order: "sort_order", + columns: [ + enumeration("slot", ["card", "body"], { required: true }), + enumeration( + "type", + [ + "heading", + "subheading", + "paragraph", + "list", + "links", + "quote", + "image", + "divider", + "video", + "button", + "callout", + "schedule", + ], + { required: true }, + ), + text("text"), + text("media"), + url("href"), + text("alt"), + text("cite"), + ], + children: [ + { + key: "items", + table: "content_block_items", + owner: { column: "block_id" }, + order: "sort_order", + columns: [ + text("text", { required: true }), + text("detail"), + url("url"), + // Schedule entries only (034_schedule_block.sql). + text("day"), + text("time"), + text("location"), + text("person_id"), + text("description"), + text("media"), + text("media_alt"), + text("map"), + ], + }, + ], +}); + +/* Hosts. One row is one host, ordered, each either an organization + or a person. The CHECK on event_hosts rejects both and the blank + filter drops neither, so the only bad row that reaches SQLite is + one with both selects filled, and that comes back keyed to the + row like any other field error. + + Not parameterised the way links and blocks are: this table is + events-only, and the owner column says so. + + sort_order isn't declared. The engine writes it from the row's + position because `order` is "sort_order", which is what makes + the first row the one v_events takes the logo and colour from. */ +export const hostsChild = { + key: "event_hosts", + table: "event_hosts", + owner: { column: "event_id" }, + order: "sort_order", + columns: [text("org_id"), text("person_id")], +}; diff --git a/server/src/admin-schema/events.js b/server/src/admin-schema/events.js new file mode 100644 index 0000000..6274dfb --- /dev/null +++ b/server/src/admin-schema/events.js @@ -0,0 +1,113 @@ +import { text, int, bool, date, time, enumeration, placeColumns, timelineExtension, linksChild, blocksChild, hostsChild } from "./columns.js"; + +/* ── Events ──────────────────────────────────────────────────── */ + +/* Column suffixes for the series weekday flags, Sunday first to + match Date#getDay. */ +const SERIES_WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; + +export const events = { + key: "events", + table: "events", + idColumn: "id", + idKind: "slug", + concurrency: "updated_at", + + list: { + columns: [ + "id", + "title", + "scope_id", + "event_type", + "date_label", + "starts_on", + "status", + "is_published", + "is_listed", + "updated_at", + ], + // No host filter: hosts are rows in another table now, and the + // engine's filters are columns on this one. The events a host + // owns are on that host's own page. + filters: ["scope_id", "event_type", "status", "is_published", "is_listed"], + search: ["title", "id", "theme"], + order: "starts_on IS NULL, starts_on DESC, title", + }, + + columns: [ + text("scope_id", { required: true }), + + // What kind of gathering, as against scope_id's whose gathering + // it is. Declared required even though the column has a + // DEFAULT: every select renders a blank first option, so without + // it a new event files itself as a retreat while nobody is + // looking. An existing row always loads with its value set, so + // this only ever asks on create. + enumeration( + "event_type", + ["retreat", "class", "workshop", "meeting", "other"], + { required: true }, + ), + + text("title", { required: true }), + text("theme"), + text("tagline"), + date("starts_on"), + date("ends_on"), + text("date_label"), + enumeration("status", ["upcoming", "past", "cancelled"]), + ...placeColumns, + text("org_logo"), + text("event_logo"), + text("color"), + text("card_image"), + bool("is_published"), + bool("is_listed"), + bool("in_timeline"), + + // A repeating schedule. Columns rather than a side table: the + // schedule is always exactly one per event, and the public view + // is SELECT e.*, so it reaches the site with no join. Ignored + // while is_series is 0. The events table in the schema says + // what each means. + bool("is_series"), + enumeration("series_frequency", ["weekly", "monthly_date", "monthly_weekday"]), + int("series_interval"), + ...SERIES_WEEKDAYS.map((day) => bool(`series_${day}`)), + time("series_start_time"), + time("series_end_time"), + int("series_count"), + ], + + extensions: [timelineExtension("event")], + + children: [ + hostsChild, + linksChild("event"), + blocksChild("event"), + { + key: "event_people", + table: "event_people", + owner: { column: "event_id" }, + order: "sort_order", + columns: [ + text("person_id", { required: true }), + enumeration( + "role", + [ + "speaker", + "leader", + "facilitator", + "host", + "musician", + "volunteer", + "attendee", + ], + { required: true }, + ), + text("title"), + bool("is_public"), + ], + }, + ], +}; diff --git a/server/src/admin-schema/frontPage.js b/server/src/admin-schema/frontPage.js new file mode 100644 index 0000000..6fe3bcd --- /dev/null +++ b/server/src/admin-schema/frontPage.js @@ -0,0 +1,126 @@ +import { text, url, int, bool, enumeration, featuredCardsChild } from "./columns.js"; + +/* ── Front page ────────────────────────────────────────────────── + + A singleton: one row, id 'home', seeded by the schema and never + created by the admin. `singleton` tells the engine to refuse create + and delete, and the CHECK on front_page.id is what makes a second + row impossible even without it. + + Every collection here is owned by page_id and replaced wholesale. + That is safe for the same reason it is for links and blocks + (nothing has a foreign key into these tables), and paths carry + their actions as a nested collection, the shape content blocks + and their items already use. */ + +export const frontPage = { + key: "front_page", + table: "front_page", + idColumn: "id", + idKind: "slug", + singleton: "home", + concurrency: "updated_at", + + list: { + columns: ["id", "headline", "hero_backdrop", "hero_feature", "updated_at"], + filters: [], + search: [], + order: "id", + }, + + columns: [ + enumeration("hero_backdrop", ["brand", "photos"]), + enumeration("hero_feature", ["none", "livestream", "video", "event"]), + text("hero_event_id"), + text("eyebrow"), + text("headline"), + text("subhead"), + text("primary_label"), + url("primary_url"), + text("secondary_label"), + url("secondary_url"), + int("slide_seconds"), + url("livestream_url"), + text("livestream_title"), + url("video_url"), + text("video_title"), + text("countdown_event_id"), + text("countdown_scope_id"), + enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]), + ], + + children: [ + { + key: "slides", + table: "front_page_slides", + owner: { column: "page_id" }, + order: "sort_order", + columns: [ + text("media", { required: true }), + text("alt"), + text("caption"), + url("link_url"), + ], + }, + { + key: "sections", + table: "front_page_sections", + owner: { column: "page_id" }, + order: "sort_order", + columns: [ + enumeration( + "section", + ["countdown", "retreats", "calendar", "stats", "timeline", "connect", "featured"], + { required: true }, + ), + text("title"), + text("blurb"), + bool("is_hidden"), + ], + }, + { + key: "stats", + table: "front_page_stats", + owner: { column: "page_id" }, + order: "sort_order", + columns: [ + text("label", { required: true }), + enumeration("source", [ + "manual", + "years_since", + "regions", + "chapters", + "partners", + "events_held", + "retreats_held", + "people", + "awards_given", + ]), + text("value"), + text("suffix"), + text("note"), + ], + }, + featuredCardsChild("front_page"), + { + key: "paths", + table: "front_page_paths", + owner: { column: "page_id" }, + order: "sort_order", + columns: [text("label", { required: true }), text("icon"), text("blurb")], + children: [ + { + key: "actions", + table: "front_page_path_actions", + owner: { column: "path_id" }, + order: "sort_order", + columns: [ + text("label", { required: true }), + text("description"), + url("url", { required: true }), + ], + }, + ], + }, + ], +}; diff --git a/server/src/admin-schema/organizations.js b/server/src/admin-schema/organizations.js new file mode 100644 index 0000000..a4059fc --- /dev/null +++ b/server/src/admin-schema/organizations.js @@ -0,0 +1,86 @@ +import { text, int, real, bool, enumeration, placeColumns, timelineExtension, linksChild, blocksChild } from "./columns.js"; + +/* ── Organizations ───────────────────────────────────────────── */ + +export const organizations = { + key: "organizations", + table: "organizations", + idColumn: "id", + idKind: "slug", + concurrency: "updated_at", + + list: { + columns: [ + "id", + "kind", + "name", + "short_name", + "locality", + "state_code", + "is_published", + "is_listed", + "sort_order", + "updated_at", + ], + filters: ["kind", "is_published", "is_listed"], + search: ["name", "id", "locality"], + order: "kind, sort_order, name", + }, + + columns: [ + enumeration("kind", ["national", "region", "chapter", "partner"], { + required: true, + }), + text("name", { required: true }), + text("short_name"), + text("tagline"), + text("color"), + text("logo"), + ...placeColumns, + bool("is_published"), + bool("is_listed"), + int("sort_order"), + bool("in_timeline"), + ], + + extensions: [ + timelineExtension("organization"), + { + key: "region", + table: "regions", + idColumn: "id", + when: { column: "kind", value: "region" }, + columns: [ + enumeration("scope", ["domestic", "international", "virtual"], { + required: true, + }), + text("map_note"), + ], + }, + { + key: "chapter", + table: "chapters", + idColumn: "id", + when: { column: "kind", value: "chapter" }, + columns: [text("region_id"), text("meets"), text("started")], + }, + ], + + children: [ + linksChild("organization"), + blocksChild("organization"), + { + key: "region_areas", + table: "region_areas", + owner: { column: "region_id" }, + when: { column: "kind", value: "region" }, + order: "area_code", + columns: [ + text("area_code", { required: true }), + real("share"), + enumeration("edge", ["top", "bottom"]), + text("note"), + ], + }, + ], +}; diff --git a/server/src/admin-schema/people.js b/server/src/admin-schema/people.js new file mode 100644 index 0000000..32cb15e --- /dev/null +++ b/server/src/admin-schema/people.js @@ -0,0 +1,99 @@ +import { text, int, bool, date, affiliationRole, linksChild, blocksChild } from "./columns.js"; + +/* ── People ──────────────────────────────────────────────────── */ + +export const people = { + key: "people", + table: "people", + idColumn: "id", + idKind: "slug", + concurrency: "updated_at", + + list: { + columns: [ + "id", + "display_name", + "sort_name", + "tagline", + "locality", + "is_published", + "is_listed", + "updated_at", + ], + filters: ["is_published", "is_listed"], + search: ["display_name", "sort_name", "id"], + order: "sort_name, display_name", + }, + + columns: [ + text("display_name", { required: true }), + text("sort_name"), + text("pronouns"), + text("tagline"), + text("photo"), + text("bio"), + text("primary_org_id"), + text("public_email"), + text("public_phone"), + text("locality"), + text("state_code"), + text("country"), + text("location_label"), + bool("is_published"), + bool("is_listed"), + ], + + extensions: [ + { + key: "private", + table: "person_private", + idColumn: "person_id", + readRole: "editor", // viewers don't see birth dates, addresses, phones + touch: true, // has its own updated_at with no trigger behind it + columns: [ + date("birth_date"), + text("private_email"), + text("private_phone"), + text("address"), + text("notes"), + ], + }, + ], + + children: [ + linksChild("person"), + blocksChild("person"), + { + key: "affiliations", + table: "affiliations", + owner: { column: "person_id" }, + + // sort_order is where this person sits on that team, so it + // belongs to the team's editor. reindex: false stops this + // form renumbering by row position; declaring the column + // keeps the team's value intact across a save here. + reindex: false, + order: "org_id, team_id, sort_order", + + columns: [ + text("org_id", { required: true }), + text("team_id"), + ...affiliationRole, + int("sort_order"), + ], + }, + { + key: "person_awards", + table: "person_awards", + owner: { column: "person_id" }, + order: "awarded_on", + columns: [ + text("award_id", { required: true }), + text("event_id"), + date("awarded_on"), + text("citation"), + bool("is_public"), + ], + }, + ], +}; diff --git a/server/src/admin-schema/siteSettings.js b/server/src/admin-schema/siteSettings.js new file mode 100644 index 0000000..2a7b86a --- /dev/null +++ b/server/src/admin-schema/siteSettings.js @@ -0,0 +1,58 @@ +import { THEME_TOKENS, checkTheme } from "../theme.js"; +import { text, enumeration } from "./columns.js"; + +/* ── Site settings (035_site_settings.sql) ────────────────────── + A singleton of overrides for what site.json says: name, + description, preview image, icons, search indexing, and static + pages' titles and intros. Superadmins only. pageMeta.js merges it + over site.json. */ +export const siteSettings = { + key: "site_settings", + table: "site_settings", + idColumn: "id", + idKind: "slug", + singleton: "site", + concurrency: "updated_at", + writeRole: "superadmin", + + list: { + columns: ["id", "site_name", "updated_at"], + filters: [], + search: [], + order: "id", + }, + + columns: [ + text("site_name"), + text("description"), + text("preview_image"), + text("favicon"), + text("apple_touch_icon"), + enumeration("indexing", ["on", "off"]), + text("privacy_email"), + ], + + children: [ + { + key: "pages", + table: "site_setting_pages", + owner: { column: "settings_id" }, + order: "sort_order", + columns: [text("path", { required: true }), text("title"), text("description")], + }, + { + key: "colors", + table: "site_setting_colors", + owner: { column: "settings_id" }, + order: "sort_order", + columns: [ + enumeration("token", THEME_TOKENS, { required: true }), + text("light"), + text("dark"), + ], + }, + ], + + // Refuses a palette that would make text hard to read (theme.js). + check: checkTheme, +}; diff --git a/server/src/admin-schema/teams.js b/server/src/admin-schema/teams.js new file mode 100644 index 0000000..5e7ee4b --- /dev/null +++ b/server/src/admin-schema/teams.js @@ -0,0 +1,66 @@ +import { text, int, bool, affiliationRole, linksChild, blocksChild } from "./columns.js"; + +/* ── Teams ───────────────────────────────────────────────────── */ + +// A team belongs to exactly one organization, and affiliations +// point at the pair (team_id, org_id) rather than the team alone. +// Two consequences the form has to live with: +// +// · org_id cannot be changed once anyone is filed under the +// team. The composite foreign key has no ON UPDATE CASCADE, so +// SQLite aborts the UPDATE. That surfaces as a constraint +// error, which is the correct answer: reassign the members +// first. +// +// · deleting a team with members fails the same way, rather than +// quietly detaching them. Emptying the members list first is +// now something the form can do. +export const teams = { + key: "teams", + table: "teams", + idColumn: "id", + idKind: "slug", + concurrency: "updated_at", + + list: { + columns: ["id", "org_id", "name", "tagline", "is_published", "is_listed", "sort_order", "updated_at"], + filters: ["org_id", "is_published", "is_listed"], + search: ["name", "id", "tagline"], + order: "org_id, sort_order, name", + }, + + columns: [ + text("org_id", { required: true }), + text("name", { required: true }), + text("tagline"), + text("color"), + text("logo"), + bool("is_published"), + bool("is_listed"), + int("sort_order"), + ], + + children: [ + // 'team' is already a valid owner_kind in both polymorphic + // tables, and teams_cleanup drops the rows on delete, so a team + // page comes free. + linksChild("team"), + blocksChild("team"), + { + key: "members", + table: "affiliations", + + // org_id is inherited from the team rather than asked for: + // the composite foreign key (team_id, org_id) means a member + // of this team can only belong to this team's organization, + // so a second dropdown could only ever be wrong. + owner: { column: "team_id", inherit: { org_id: "org_id" } }, + + // Row position is the order they appear on the public site. + // This is the only editor that writes it. + order: "sort_order", + + columns: [text("person_id", { required: true }), ...affiliationRole], + }, + ], +}; diff --git a/server/src/admin-schema/timeline.js b/server/src/admin-schema/timeline.js new file mode 100644 index 0000000..9ee80e1 --- /dev/null +++ b/server/src/admin-schema/timeline.js @@ -0,0 +1,63 @@ +import { text, date, time, enumeration, timelineFields } from "./columns.js"; + +/* ── Timeline ────────────────────────────────────────────────── */ + +// The history page's spine, and the only entity whose id the table +// assigns. There is nothing to slug: an entry referencing an event has +// no name of its own, and one gets created every time somebody ticks a +// checkbox. idKind "auto" is what lets createRow skip the id entirely. +// +// ref_kind and ref_id are writable here and only here. The extension on +// events and organizations owns those two columns for rows it created, +// which is why they aren't in timelineFields. +// +// Deleting an entry takes its people with it (ON DELETE CASCADE) and +// nothing points at an entry, so the delete-and-reinsert child engine +// is safe on this one. +export const timeline = { + key: "timeline", + table: "timeline_entries", + idColumn: "id", + idKind: "auto", + concurrency: "updated_at", + + list: { + columns: [ + "id", + "kind", + "ref_kind", + "ref_id", + "occurred_on", + "title", + "is_featured", + "is_published", + "updated_at", + ], + filters: ["kind", "ref_kind", "is_featured", "is_published"], + search: ["title", "blurb", "meta", "ref_id"], + // Undated entries sort last rather than first, so a missing date + // reads as something to fix instead of something to scroll past. + order: "occurred_on IS NULL, occurred_on DESC, sort_order", + }, + + columns: [ + enumeration( + "kind", + ["milestone", "event", "organization", "award", "people"], + { required: true }, + ), + enumeration("ref_kind", ["event", "organization", "award", "person", "team"]), + text("ref_id"), + ...timelineFields, + ], + + children: [ + { + key: "people", + table: "timeline_entry_people", + owner: { column: "entry_id" }, + order: "sort_order", + columns: [text("person_id", { required: true }), text("note")], + }, + ], +}; diff --git a/server/src/routes/admin-entities.js b/server/src/routes/admin-entities.js index 3a85687..f8dec83 100644 --- a/server/src/routes/admin-entities.js +++ b/server/src/routes/admin-entities.js @@ -28,12 +28,12 @@ import { updateRow, deleteRow, } from "../admin-crud.js"; +import { NO_STORE } from "../shape.js"; const entities = new Hono(); entities.use("*", requireAuth); -const NO_STORE = { "Cache-Control": "no-store" }; function entityOr404(c) { const name = c.req.param("entity"); diff --git a/server/src/routes/admin.js b/server/src/routes/admin.js index 2b433b7..5914fe2 100644 --- a/server/src/routes/admin.js +++ b/server/src/routes/admin.js @@ -10,12 +10,12 @@ import { Hono } from "hono"; import { requireAuth, requireRole } from "../auth.js"; +import { NO_STORE } from "../shape.js"; const admin = new Hono(); admin.use("*", requireAuth); -const NO_STORE = { "Cache-Control": "no-store" }; const STATUSES = ["new", "read", "actioned", "archived", "spam"]; const MAX_LIMIT = 200; diff --git a/server/src/routes/auth.js b/server/src/routes/auth.js index efac38d..c86ce55 100644 --- a/server/src/routes/auth.js +++ b/server/src/routes/auth.js @@ -42,6 +42,7 @@ import { } from "../auth.js"; import { GoogleLoginError, finishLogin, googleConfig, startLogin } from "../googleAuth.js"; import { failureLimit } from "../rateLimit.js"; +import { NO_STORE } from "../shape.js"; // On top of the per-IP limit where /login is mounted: five wrong // passwords for one email in 15 minutes locks that email for the @@ -54,7 +55,6 @@ const auth = new Hono(); // so both paths cost the same. Computed once at import. const DUMMY_HASH = hashPassword("this password is never correct"); -const NO_STORE = { "Cache-Control": "no-store" }; auth.post("/login", async (c) => { let body; diff --git a/server/src/routes/clips.js b/server/src/routes/clips.js index d96adbb..70586ad 100644 --- a/server/src/routes/clips.js +++ b/server/src/routes/clips.js @@ -39,13 +39,13 @@ import { saveToLibrary, toolVersions, } from "../clips.js"; +import { NO_STORE } from "../shape.js"; const clips = new Hono(); clips.use("/clips", requireAuth, requireRole("admin")); clips.use("/clips/*", requireAuth, requireRole("admin")); -const NO_STORE = { "Cache-Control": "no-store" }; const RECENT = 50; diff --git a/server/src/routes/content.js b/server/src/routes/content.js index f215ab8..b65cc0f 100644 --- a/server/src/routes/content.js +++ b/server/src/routes/content.js @@ -57,6 +57,7 @@ import { json, loadBlocks, loadLinks, + loadOwned, marks, paragraphs, shapeSeries, @@ -492,9 +493,7 @@ content.get("/events/:id", (c) => { if (!row) return c.json({ error: "No such event" }, 404); - const links = loadLinks(db, "event", [id]).get(id) ?? []; - const cards = loadBlocks(db, "event", [id], "card").get(id) ?? []; - const body = loadBlocks(db, "event", [id], "body").get(id) ?? []; + const { links, cards, body } = loadOwned(db, "event", id); const hosts = loadHosts(db, [id]).get(id) ?? []; const people = db @@ -602,9 +601,7 @@ content.get("/organizations/:id", (c) => { if (!row) return c.json({ error: "No such organization" }, 404); - const links = loadLinks(db, "organization", [id]).get(id) ?? []; - const cards = loadBlocks(db, "organization", [id], "card").get(id) ?? []; - const body = loadBlocks(db, "organization", [id], "body").get(id) ?? []; + const { links, cards, body } = loadOwned(db, "organization", id); const organization = shapeOrganization(row, links, cards, body); const one = [organization]; @@ -684,9 +681,7 @@ content.get("/teams/:id", (c) => { if (!row) return c.json({ error: "No such team" }, 404); - const links = loadLinks(db, "team", [id]).get(id) ?? []; - const cards = loadBlocks(db, "team", [id], "card").get(id) ?? []; - const body = loadBlocks(db, "team", [id], "body").get(id) ?? []; + const { links, cards, body } = loadOwned(db, "team", id); return json(c, { team: { ...shapeTeam(row, links, cards), blocks: body } }); }); diff --git a/server/src/routes/media.js b/server/src/routes/media.js index 6e39ad8..23a76b3 100644 --- a/server/src/routes/media.js +++ b/server/src/routes/media.js @@ -37,12 +37,12 @@ import { store, } from "../media.js"; import { fetchImage, previewLink } from "../linkPreview.js"; +import { NO_STORE } from "../shape.js"; const media = new Hono(); media.use("*", requireAuth); -const NO_STORE = { "Cache-Control": "no-store" }; const MAX_LIST = 500; diff --git a/server/src/routes/pages.js b/server/src/routes/pages.js index c0e34c6..7a03596 100644 --- a/server/src/routes/pages.js +++ b/server/src/routes/pages.js @@ -36,7 +36,7 @@ import { fileURLToPath } from "node:url"; import { Hono } from "hono"; import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js"; -import { CACHE } from "../shape.js"; +import { CACHE, NO_STORE } from "../shape.js"; const here = path.dirname(fileURLToPath(import.meta.url)); @@ -117,7 +117,7 @@ pages.get("*", (c, next) => { `pages: serving ${pathname} without its metadata: ${err.message}` + (err.code === "ENOENT" ? " (set SITE_CONFIG to the deployed site.json)" : ""), ); - return c.html(html, 200, { "Cache-Control": "no-store" }); + return c.html(html, 200, NO_STORE); } // no-cache: a browser may keep the page but asks again each time. diff --git a/server/src/routes/panel.js b/server/src/routes/panel.js index 4c13242..4b3a78e 100644 --- a/server/src/routes/panel.js +++ b/server/src/routes/panel.js @@ -26,13 +26,13 @@ import { Hono } from "hono"; import { requireAuth, requireRole, ROLES } from "../auth.js"; import { tx } from "../db.js"; +import { NO_STORE } from "../shape.js"; const panel = new Hono(); panel.use("*", requireAuth); panel.use("*", requireRole("superadmin")); -const NO_STORE = { "Cache-Control": "no-store" }; /* The counts on the overview. Table name is a literal from this list, never anything off the wire. */ diff --git a/server/src/routes/people.js b/server/src/routes/people.js index 817f4d3..8200c24 100644 --- a/server/src/routes/people.js +++ b/server/src/routes/people.js @@ -21,7 +21,7 @@ import { Hono } from "hono"; -import { asBool, json, loadBlocks, loadLinks, marks, paragraphs, splitLinks } from "../shape.js"; +import { asBool, json, loadOwned, marks, paragraphs, splitLinks } from "../shape.js"; const people = new Hono(); @@ -175,9 +175,7 @@ people.get("/people/:id", (c) => { if (!row) return c.json({ error: "No such person" }, 404); - const links = loadLinks(db, "person", [id]).get(id) ?? []; - const cards = loadBlocks(db, "person", [id], "card").get(id) ?? []; - const body = loadBlocks(db, "person", [id], "body").get(id) ?? []; + const { links, cards, body } = loadOwned(db, "person", id); const { actions, socials, website, instagram } = splitLinks(links); // Current first, then most recently ended. Within each, the same diff --git a/server/src/shape.js b/server/src/shape.js index c743f3f..5ea0259 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -302,10 +302,23 @@ export function loadFeaturedCards(db, ownerKind, ownerId) { export { asBool }; +/* One record's links, card blocks and body blocks: what every detail + page sends beside the record itself. */ +export function loadOwned(db, ownerKind, id) { + return { + links: loadLinks(db, ownerKind, [id]).get(id) ?? [], + cards: loadBlocks(db, ownerKind, [id], "card").get(id) ?? [], + body: loadBlocks(db, ownerKind, [id], "body").get(id) ?? [], + }; +} + /* Public reads may be cached a minute, and served a little stale while a fresh copy is fetched. json() sends a body with it. */ export const CACHE = "public, max-age=60, stale-while-revalidate=300"; export const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE }); +// Admin reads and anything personal: never kept by a browser or proxy. +export const NO_STORE = { "Cache-Control": "no-store" }; + // "?,?,?" for an IN (...) list of n values. export const marks = (n) => Array(n).fill("?").join(","); diff --git a/server/src/theme.js b/server/src/theme.js index bc55b39..bccc7ee 100644 --- a/server/src/theme.js +++ b/server/src/theme.js @@ -4,9 +4,9 @@ The admin's palette (Panel → Site settings → Colours, table site_setting_colors) over the site's own colour tokens. - THEME_DEFAULTS must match @theme and the dark block in - src/index.css: the same tokens, the same light and dark values. - A blank override keeps the default. + The defaults are THEME_DEFAULTS (themeDefaults.js), which the + build checks against src/index.css. A blank override keeps the + default. themeCss() is written into every page's (pageMeta.js). It goes into the same cascade layers as index.css (theme for @@ -20,22 +20,9 @@ ═══════════════════════════════════════════════════════════════ */ import { HttpError } from "./admin-crud.js"; +import { THEME_DEFAULTS } from "./themeDefaults.js"; -// light dark -export const THEME_DEFAULTS = { - ink: ["#073d4a", "#eaf6f8"], - body: ["#26454c", "#cde0e4"], - muted: ["#4a6b72", "#9fb9bf"], - link: ["#0f7183", "#5ccbdc"], - brand: ["#138ba0", "#2aa7bc"], - action: ["#0f7183", "#0f7183"], - "action-hover": ["#0b5c6a", "#0b5c6a"], - surface: ["#ffffff", "#0c1d21"], - tint: ["#eef9fb", "#11292e"], - "tint-soft": ["#f6fbfc", "#0f2428"], - danger: ["#b3261e", "#ff8a80"], - "danger-tint": ["#fdf3f2", "#3b1714"], -}; +export { THEME_DEFAULTS }; export const THEME_TOKENS = Object.keys(THEME_DEFAULTS); diff --git a/server/src/themeDefaults.js b/server/src/themeDefaults.js new file mode 100644 index 0000000..ec5f22a --- /dev/null +++ b/server/src/themeDefaults.js @@ -0,0 +1,29 @@ +/* ═══════════════════════════════════════════════════════════════ + THEME DEFAULTS + + The site's own colour tokens, light and dark: the one list both + the server (theme.js: contrast check, overrides) and the admin + (Site settings → Colours: defaults shown) read. No imports, so the + browser bundle can take it too. + + src/index.css holds the same values as CSS (@theme and its dark + block), since CSS can't import this. The build checks the two + agree and stops if they don't (themeDefaultsCheck in + vite.config.ts). Change a colour here and there together. + ═══════════════════════════════════════════════════════════════ */ + +// light dark +export const THEME_DEFAULTS = { + ink: ["#073d4a", "#eaf6f8"], + body: ["#26454c", "#cde0e4"], + muted: ["#4a6b72", "#9fb9bf"], + link: ["#0f7183", "#5ccbdc"], + brand: ["#138ba0", "#2aa7bc"], + action: ["#0f7183", "#0f7183"], + "action-hover": ["#0b5c6a", "#0b5c6a"], + surface: ["#ffffff", "#0c1d21"], + tint: ["#eef9fb", "#11292e"], + "tint-soft": ["#f6fbfc", "#0f2428"], + danger: ["#b3261e", "#ff8a80"], + "danger-tint": ["#fdf3f2", "#3b1714"], +}; diff --git a/src/assets/logos/NGU_Logo_WhiteBG.svg b/src/assets/logos/NGU_Logo_WhiteBG.svg deleted file mode 100644 index 3202fa3..0000000 --- a/src/assets/logos/NGU_Logo_WhiteBG.svg +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - Next Generation - of Unity - - - - diff --git a/src/components/OrgLogo.tsx b/src/components/OrgLogo.tsx new file mode 100644 index 0000000..1ee2074 --- /dev/null +++ b/src/components/OrgLogo.tsx @@ -0,0 +1,39 @@ +/* ═══════════════════════════════════════════════════════════════ + ORG LOGO + + An organization's logo, or its initials in a square in its colour + when there's no file or it fails to load. Decorative: the name is + always right beside it. Used by the organization lists and the + chapter map. + ═══════════════════════════════════════════════════════════════ */ + +import Logo from './Logo.tsx' +import { accentText } from '../lib/color.ts' +import { mediaUrl } from '../lib/media.ts' +import { initialsFor } from '../lib/organizations.ts' + +export default function OrgLogo({ + org, + color, + size = 'h-14 w-14', +}: { + org: { logo?: string | null; name: string } + color: string + size?: string +}) { + return ( +