diff --git a/server/src/admin-schema/columns.js b/server/src/admin-schema/columns.js index 0832550..49a0f15 100644 --- a/server/src/admin-schema/columns.js +++ b/server/src/admin-schema/columns.js @@ -150,6 +150,7 @@ export const blocksChild = (ownerKind) => ({ "schedule", "table", "cards", + "people", ], { required: true }, ), @@ -158,6 +159,8 @@ export const blocksChild = (ownerKind) => ({ url("href"), text("alt"), text("cite"), + // People blocks only (054): whose team's tiles to show. + text("team_id"), ], children: [ { @@ -200,5 +203,6 @@ export const hostsChild = { table: "event_hosts", owner: { column: "event_id" }, order: "sort_order", - columns: [text("org_id"), text("person_id")], + // team_id (054): an organization host's team, shown in its place. + columns: [text("org_id"), text("person_id"), text("team_id")], }; diff --git a/server/src/migrations/054_people_blocks_host_teams.sql b/server/src/migrations/054_people_blocks_host_teams.sql new file mode 100644 index 0000000..ecb39c0 --- /dev/null +++ b/server/src/migrations/054_people_blocks_host_teams.sql @@ -0,0 +1,140 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 054 PEOPLE BLOCKS, HOST TEAMS, THE ORGANIZATION PAGE +-- +-- A content block of type 'people': a team's people tiles, people +-- picked one by one (items, each with a title), or both. The team +-- is a new column, content_blocks.team_id; a picked person rides on +-- the item's person_id, as a schedule entry's does. ContentBlocks.tsx +-- draws it with PeopleTiles. The type CHECK changes, so the table is +-- rebuilt as 045 did (legacy_alter_table around the rename, then its +-- index and owner trigger again). +-- +-- An event's organization host can name a team to show instead: +-- event_hosts.team_id, any organization's team. The event page then +-- reads "Hosted by " linked to the team's page. v_event_hosts +-- carries it (and v_events, which reads v_event_hosts, is made again +-- around it, unchanged). +-- +-- The Leadership page is now the Organization page, at /organization: +-- a page title or intro saved for /leadership in Site settings moves +-- with it. +-- ═══════════════════════════════════════════════════════════════ + +-- ── Host teams ───────────────────────────────────────────────── + +ALTER TABLE event_hosts ADD COLUMN team_id TEXT REFERENCES teams (id) ON DELETE SET NULL; + +DROP VIEW v_events; +DROP VIEW v_event_hosts; + +CREATE VIEW v_event_hosts AS +SELECT + eh.id, + eh.event_id, + eh.sort_order, + CASE WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END + AS host_kind, + COALESCE(eh.org_id, eh.person_id) AS host_id, + COALESCE(o.name, p.display_name) AS host_name, + o.kind AS host_org_kind, + o.logo AS host_logo, + o.color AS host_color, + p.photo AS host_photo, + COALESCE(o.is_published, p.is_published) AS host_is_published, + t.id AS host_team_id, + t.name AS host_team_name +FROM event_hosts eh +LEFT JOIN organizations o ON o.id = eh.org_id +LEFT JOIN people p ON p.id = eh.person_id +LEFT JOIN teams t ON t.id = eh.team_id AND eh.org_id IS NOT NULL AND t.is_published = 1; + +CREATE VIEW v_events AS +SELECT + e.*, + h.host_kind, + h.host_id, + h.host_name, + h.host_org_kind, + COALESCE(e.org_logo, h.host_logo) AS effective_org_logo, + COALESCE(e.color, h.host_color) AS effective_color, + COALESCE( + e.status, + CASE WHEN e.ends_on IS NOT NULL AND e.ends_on < date('now') + THEN 'past' ELSE 'upcoming' END + ) AS effective_status +FROM events e +LEFT JOIN v_event_hosts h + ON h.id = ( + SELECT x.id + FROM v_event_hosts x + WHERE x.event_id = e.id + ORDER BY x.sort_order, x.id + LIMIT 1 + ); + + +-- ── People blocks ────────────────────────────────────────────── + +CREATE TABLE content_blocks_new ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + owner_kind TEXT NOT NULL + CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), + owner_id TEXT NOT NULL, + slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), + sort_order INTEGER NOT NULL DEFAULT 0, + + type TEXT NOT NULL + CHECK (type IN ('heading', 'subheading', 'paragraph', + 'list', 'links', 'quote', 'image', 'divider', + 'video', 'button', 'callout', 'schedule', 'table', 'cards', + 'people')), + text TEXT, + media TEXT, + href TEXT, + alt TEXT, + cite TEXT, + team_id TEXT REFERENCES teams (id) ON DELETE SET NULL +) STRICT; + +INSERT INTO content_blocks_new + (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite) +SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite + FROM content_blocks; + +PRAGMA legacy_alter_table = ON; +DROP TABLE content_blocks; +ALTER TABLE content_blocks_new RENAME TO content_blocks; +PRAGMA legacy_alter_table = OFF; + +CREATE INDEX content_blocks_owner_idx + ON content_blocks (owner_kind, owner_id, slot, sort_order); + + +-- ── The Organization page ────────────────────────────────────── + +UPDATE site_setting_pages SET path = '/organization' WHERE path = '/leadership'; + + +-- ── Triggers last (see CLAUDE.md, Migrations) ── + +CREATE TRIGGER content_blocks_owner_exists +BEFORE INSERT ON content_blocks +BEGIN + SELECT CASE + WHEN new.owner_kind = 'event' + AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such event') + WHEN new.owner_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such organization') + WHEN new.owner_kind = 'person' + AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such person') + WHEN new.owner_kind = 'team' + AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such team') + WHEN new.owner_kind = 'blog_post' + AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such blog post') + END; +END; diff --git a/server/src/routes/content.js b/server/src/routes/content.js index 943dbbe..820086a 100644 --- a/server/src/routes/content.js +++ b/server/src/routes/content.js @@ -88,7 +88,8 @@ function loadHosts(db, ids) { const rows = db .prepare( - `SELECT event_id, host_kind, host_id, host_name, host_org_kind + `SELECT event_id, host_kind, host_id, host_name, host_org_kind, + host_team_id, host_team_name FROM v_event_hosts WHERE event_id IN (${marks(ids.length)}) AND host_is_published = 1 @@ -115,6 +116,9 @@ function shapeHost(row) { // Which of /regions, /groups, /partners the slug belongs to. // Null for a person, whose route needs no disambiguating. org_kind: row.host_org_kind, + // The team an organization host is shown as, when one is set + // (and published): the event page names and links it instead. + team: row.host_team_id ? { id: row.host_team_id, name: row.host_team_name } : null, }; } diff --git a/server/src/seed-showcase.js b/server/src/seed-showcase.js index 5f16645..550f6f9 100644 --- a/server/src/seed-showcase.js +++ b/server/src/seed-showcase.js @@ -144,6 +144,10 @@ const ALL_BLOCKS = [ { text: "A card with a picture", detail: "Its description, up to three lines, under the title. The whole card is the link.", url: "/retreats", media: IMAGE }, { text: "An outside link, text only", detail: "The card shows the site it goes to above the title.", url: "https://example.org" }, ]], + ["subheading", { text: "People" }], + ["people", { team_id: TEAM }, [ + { person_id: PERSON, text: "Picked as an item, with a title" }, + ]], ]; /* A record page's body: a handful of types, so it reads like a @@ -426,7 +430,8 @@ tx(db, () => { is_published: 1, is_listed: LISTED, }); - insert("event_hosts", { event_id: PAST, org_id: REGION, sort_order: 0 }); + // Hosted by the region, shown as its team (054). + insert("event_hosts", { event_id: PAST, org_id: REGION, team_id: TEAM, sort_order: 0 }); insert("event_people", { event_id: PAST, person_id: PERSON, role: "host", is_public: 1, sort_order: 0 }); blocks("event", PAST, "card", cardText("past event")); diff --git a/server/src/shape.js b/server/src/shape.js index 5ea0259..4a23395 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -66,7 +66,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") { const blockRows = db .prepare( - `SELECT id, owner_id, type, text, media, href, alt, cite + `SELECT id, owner_id, type, text, media, href, alt, cite, team_id FROM content_blocks WHERE owner_kind = ? AND slot = ? AND owner_id IN (${placeholders(ids.length)}) ORDER BY owner_id, sort_order`, @@ -85,6 +85,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") { href: row.href, alt: row.alt, cite: row.cite, + team_id: row.team_id, items: [], }; byId.set(row.id, block); diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx index 0650497..1d53d3a 100644 --- a/src/components/ContentBlocks.tsx +++ b/src/components/ContentBlocks.tsx @@ -27,6 +27,9 @@ cards items as link cards, up to three in a row: text the title, detail, url, media the picture + people team_id's members as people tiles, then + items as more tiles: person, text their + title (an unpublished person is left out) divider nothing "Formatted" is InlineText.tsx: **bold**, *italic*, [text](url), @@ -38,6 +41,7 @@ ═══════════════════════════════════════════════════════════════ */ import { mediaUrl } from '../lib/media.ts' +import PeopleTiles from './PeopleTiles.tsx' import type { ContentBlock, ContentBlockItem } from '../lib/useContent.ts' import { Anchor, Inline, Paragraphs, isExternalUrl } from './InlineText.tsx' import VideoPlayer from './VideoPlayer.tsx' @@ -326,6 +330,19 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string; if (!block.items?.length) return null return + case 'people': { + const picked = (block.items ?? []) + .filter((item) => item.person) + .map((item) => ({ peopleslug: item.person!.id, title: item.text || null })) + if (!block.team_id && picked.length === 0) return null + return ( +
+ {block.team_id && } + {picked.length > 0 && } +
+ ) + } + case 'divider': return
diff --git a/src/components/admin/fields.tsx b/src/components/admin/fields.tsx index 94b50a5..57367e5 100644 --- a/src/components/admin/fields.tsx +++ b/src/components/admin/fields.tsx @@ -163,10 +163,14 @@ export function setPath(object, path, value) { /* ── Conditional fields ──────────────────────────────────────── */ +/* `when: { path, value }` shows a field when the other field holds + that value (or one of a list); `when: { path, filled: true }` when + it holds anything at all. */ export function fieldShown(field, row, parent?) { if (!field.when) return true; - const want = Array.isArray(field.when.value) ? field.when.value : [field.when.value]; const source = field.when.scope === "parent" ? parent : row; + if (field.when.filled) return Boolean(source?.[field.when.path]); + const want = Array.isArray(field.when.value) ? field.when.value : [field.when.value]; return want.includes(source?.[field.when.path]); } diff --git a/src/lib/adminSchema/shared.ts b/src/lib/adminSchema/shared.ts index 9306c28..e994c81 100644 --- a/src/lib/adminSchema/shared.ts +++ b/src/lib/adminSchema/shared.ts @@ -230,6 +230,11 @@ export const linksChild = { The first row supplies the logo and color when the event sets neither, so the order here is data rather than a display choice. + + An organization host can name a team (any organization's) to show + in its place: the event page reads "Hosted by" that team, linked + to its page, while the logo and color still come from the + organization. A person supplies neither: there is no color on a person and a headshot is not a logo, so a person-hosted event with no color of its own falls through to the section default. */ @@ -259,6 +264,15 @@ export const hostsChild = { blankLabel: "Default: none", help: "Use if the host is an individual, choose between person and org host, not both.", }, + { + path: "team_id", + label: "Shown as team", + widget: "select", + optionsFrom: "teams", + blankLabel: "Default: the organization", + help: "Optional: a team to name as the host instead, eg. the retreat team. Any organization's team.", + when: { path: "org_id", filled: true }, + }, ], }; @@ -280,6 +294,7 @@ export const BLOCK_TYPES = [ ["schedule", "Schedule", "Entries in one tab per day, each folding out for more. The text is an optional intro."], ["table", "Table", "A grid of text, eg. a comparison chart: one row per line, cells split by |, the first row the header."], ["cards", "Link cards", "Cards with a picture, title and description, each a link to a page or a file, like a link shared in a chat; up to three in a row. Paste a link and press Fetch preview, or Choose a file."], + ["people", "People", "People tiles: a team's members, or people picked one by one as items (each with their title), or both."], ["divider", "Divider", "A thin line between parts."], ]; @@ -288,6 +303,8 @@ export const SCHEDULE_ENTRY = { scope: "parent", path: "type", value: "schedule" /* Item fields for a link card, and for every other kind of item. */ export const CARD_ITEM = { scope: "parent", path: "type", value: "cards" }; export const NOT_CARD_ITEM = { scope: "parent", path: "type", value: ["list", "links", "schedule"] }; +/* An item that's a person on a people block. */ +export const PEOPLE_ITEM = { scope: "parent", path: "type", value: "people" }; export const blockTypeLabel = (type) => BLOCK_TYPES.find(([value]) => value === type)?.[1] ?? type; @@ -384,13 +401,22 @@ export const blocksChild = { when: { path: "type", value: "image" }, help: "Describes the picture for someone who can't see it, eg. Campers around a fire at dusk", }, + { + path: "team_id", + label: "Team", + widget: "select", + optionsFrom: "teams", + blankLabel: "Default: none, just the people below", + help: "Shows the team's members as tiles, its leads first. People added as items show after it.", + when: { path: "type", value: "people" }, + }, ], children: [ { key: "items", label: "Items", addLabel: "Add item", - when: { path: "type", value: ["list", "links", "schedule", "cards"] }, + when: { path: "type", value: ["list", "links", "schedule", "cards", "people"] }, title: (row) => [row.day, row.time, row.text].filter(Boolean).join(" · ") || "New item", blank: { text: "" }, fields: [ @@ -412,7 +438,16 @@ export const blocksChild = { help: "A page on this site (eg. /retreats), anywhere else, or a file (Choose a file). Fetch preview fills the title, description and picture from a page; a file fills its name and first-page picture.", when: CARD_ITEM, }, - { path: "text", label: "Text", required: true, help: "Schedules: the entry's title. Cards: the card's title" }, + { + path: "person_id", + label: "Person", + widget: "select", + optionsFrom: "people", + required: true, + help: "Shown as a tile with their photo, linked to their page", + when: PEOPLE_ITEM, + }, + { path: "text", label: "Text", required: true, help: "Schedules: the entry's title. Cards: the card's title. People: their title on the tile, eg. Speaker" }, { path: "location", label: "Location", diff --git a/src/lib/useContent.ts b/src/lib/useContent.ts index 7656b65..79bc338 100644 --- a/src/lib/useContent.ts +++ b/src/lib/useContent.ts @@ -38,11 +38,14 @@ export type ContentBlock = { | 'schedule' | 'table' | 'cards' + | 'people' text?: string | null media?: string | null href?: string | null /** An image's alt text. */ alt?: string | null + /** A people block's team, shown as its members' tiles. */ + team_id?: string | null /** Who a quote is by. */ cite?: string | null items?: ContentBlockItem[] @@ -84,6 +87,8 @@ export type EventHost = { id: string name: string org_kind?: string | null + /** An organization host's team, shown in its place (054). */ + team?: { id: string; name: string } | null } /* ── Events ──────────────────────────────────────────────────── */ diff --git a/src/pages/EventDetail.tsx b/src/pages/EventDetail.tsx index 95b40e9..a237a35 100644 --- a/src/pages/EventDetail.tsx +++ b/src/pages/EventDetail.tsx @@ -295,12 +295,14 @@ function Facts({ event, accent }: { event: EventRecord; accent: string }) { sentence, so they're joined with commas and an "and" rather than stacked. A host whose id didn't resolve to a route renders as plain text, refHref returns null for that, because a dead link - is worse than a name. */ + is worse than a name. An organization host with a team set shows + the team instead, linked to the team's page. */ function HostList({ hosts, accent }: { hosts: EventHost[]; accent: string }) { return ( <> {hosts.map((host, index) => { - const to = refHref(host.kind, host.id, host.org_kind) + const to = host.team ? refHref('team', host.team.id) : refHref(host.kind, host.id, host.org_kind) + const name = host.team?.name ?? host.name return ( @@ -312,10 +314,10 @@ function HostList({ hosts, accent }: { hosts: EventHost[]; accent: string }) { className="font-medium hover:underline" style={{ color: accentText(accent) }} > - {host.name} + {name} ) : ( - {host.name} + {name} )} )