From 71a470b66f61192c8d57c92fe840603a46501d16 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Sun, 27 Sep 2026 21:12:47 -0500 Subject: [PATCH] Add a Schedule content block with day tabs A schedule block's entries (migration 034) each have a day, time, title, detail, location, person and link, and fold out for a longer description, the person's photo and page, a graphic and a Google map of a place or address. Entries sit in one tab per day, in the order entered; the tab for today's weekday opens first, and a one-day schedule draws no tabs. In the editor, the entry fields show only under a schedule block: repeater `when` can now look at the parent row (scope "parent"), and a field's label can depend on the row. The block preview names an entry's person. The showcase retreat and post each have a schedule. Co-Authored-By: Claude Opus 5.5 --- docs/updating-data-in-code.md | 2 +- server/src/admin-schema.js | 9 + server/src/migrations/034_schedule_block.sql | 99 +++++++ server/src/seed-showcase.js | 24 +- server/src/shape.js | 29 +- src/components/ContentBlocks.tsx | 9 + src/components/ScheduleBlock.tsx | 270 +++++++++++++++++++ src/components/admin/fields.tsx | 58 +++- src/lib/adminSchema.ts | 67 ++++- src/lib/useContent.ts | 18 +- 10 files changed, 556 insertions(+), 29 deletions(-) create mode 100644 server/src/migrations/034_schedule_block.sql create mode 100644 src/components/ScheduleBlock.tsx diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index f96f5b6..5f1ae6e 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -175,7 +175,7 @@ also in `admin-schema.js` and a CHECK): | Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` | | Links → Platform | instagram, facebook, discord, youtube, tiktok, x, substack, spotify, linkedin | **yes**, `PLATFORMS` | `PlatformIcon.tsx` draws the icon on the button. **No CHECK and no `enumeration`**: the column is plain text, so adding one is an entry in `PLATFORMS` (`src/lib/platforms.ts`) and its icon in `src/components/PlatformIcon.tsx`, no migration. | | Content blocks → Shown in (slot) | card, body | **yes** | `paragraphs()` in `server/src/shape.js` (card), `ContentBlocks.tsx` (body) | -| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema.ts`). | +| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout, schedule | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema.ts`). | | Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` | | Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` | | Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping | diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index e8a5ac1..edc53a8 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -179,6 +179,7 @@ const blocksChild = (ownerKind) => ({ "video", "button", "callout", + "schedule", ], { required: true }, ), @@ -198,6 +199,14 @@ const blocksChild = (ownerKind) => ({ text("text", { required: true }), text("detail"), text("url"), + // Schedule entries only (034_schedule_block.sql). + text("day"), + text("time"), + text("location"), + text("person_id"), + text("description"), + text("media"), + text("map"), ], }, ], diff --git a/server/src/migrations/034_schedule_block.sql b/server/src/migrations/034_schedule_block.sql new file mode 100644 index 0000000..0655c1a --- /dev/null +++ b/server/src/migrations/034_schedule_block.sql @@ -0,0 +1,99 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 034 CONTENT BLOCKS: SCHEDULE +-- +-- A 'schedule' block: the block's items are its entries, grouped +-- into one tab per day. Each entry says when, what and where, and +-- folds out for more. The block's own text is an optional intro. +-- +-- content_block_items gains the entry's fields. A list or link-row +-- block leaves them empty: +-- +-- day the tab it sits under, eg. 'Friday'. Tabs follow +-- the order entries are in; blank means one untitled +-- day, and a schedule of one day draws no tabs +-- time '7:00pm', '9:00 to 10:30am': shown as typed +-- location where it happens, eg. 'Main Hall' +-- person_id who hosts or speaks: a people row, drawn with its +-- photo and linked to its page. ON DELETE SET NULL, +-- and an unpublished person isn't shown +-- description the fold-out text, formatted like a paragraph +-- media a graphic in the fold-out: '/uploads/…' or a URL +-- map a place or address to show on a Google map in the +-- fold-out, eg. 'Camp Hebron, Halifax PA' +-- +-- text is the entry's title, detail a line under it, url a link on +-- the title, as for list items. +-- +-- The type list is a CHECK, so content_blocks is rebuilt the way +-- 031 and 032 did it (legacy_alter_table around the rename, then +-- the index and the owner trigger again). The item columns are +-- plain ADD COLUMNs. +-- +-- PRAGMA user_version; -- reads 33 before this file +-- ═══════════════════════════════════════════════════════════════ + +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')), + text TEXT, + media TEXT, + href TEXT, + alt TEXT, + cite TEXT +) 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); + +ALTER TABLE content_block_items ADD COLUMN day TEXT; +ALTER TABLE content_block_items ADD COLUMN time TEXT; +ALTER TABLE content_block_items ADD COLUMN location TEXT; +ALTER TABLE content_block_items ADD COLUMN person_id TEXT + REFERENCES people (id) ON DELETE SET NULL; +ALTER TABLE content_block_items ADD COLUMN description TEXT; +ALTER TABLE content_block_items ADD COLUMN media TEXT; +ALTER TABLE content_block_items ADD COLUMN map TEXT; + + +-- ── 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/seed-showcase.js b/server/src/seed-showcase.js index 747f7e4..41bcb3b 100644 --- a/server/src/seed-showcase.js +++ b/server/src/seed-showcase.js @@ -16,7 +16,8 @@ /people/showcase-person person: bio, links, roles past and current, events, awards, private data /events/showcase-event upcoming retreat: hosts, billed - people, links, blocks, background + people, links, blocks, background, + a three-day schedule /events/showcase-series weekly series with times /events/showcase-past-event past event where the award was given /blog/content-block-showcase every content block type @@ -81,6 +82,23 @@ const PAST = "showcase-past-event"; /* ── Content ───────────────────────────────────────────────── */ +/* A schedule over three days, using every entry field: a plain + entry, one with a location and person, one folding out with a + description, graphic and map, one linked, and one with no day + (it lands in a tab of its own). */ +const SCHEDULE = [ + "schedule", + { text: "The weekend at a glance. Tap an entry for more." }, + [ + { day: "Friday", time: "4:00pm", text: "Arrivals and check-in", location: "Front desk" }, + { day: "Friday", time: "7:00 to 8:30pm", text: "Opening session", location: "Main Hall", person_id: "showcase-person", detail: "Welcome and worship", description: "The **opening session** sets the theme for the weekend.\n\nBring a notebook.", media: "/uploads/showcase.jpg", map: "Camp Hebron, Halifax PA" }, + { day: "Saturday", time: "9:00am", text: "Workshops", location: "Classrooms", person_id: "showcase-member-2", detail: "Pick one of three", url: "/blog/content-block-showcase" }, + { day: "Saturday", time: "7:00pm", text: "Talent night", location: "Main Hall", person_id: "showcase-member-3", description: "Sign up at the front desk by noon." }, + { day: "Sunday", time: "10:00am", text: "Closing service", location: "Chapel", map: "Main Street, Halifax PA" }, + { time: "Any time", text: "Quiet room open", location: "Library", detail: "An entry with no day" }, + ], +]; + /* Every block type, for the blog showcase. [type, fields, items?] */ const ALL_BLOCKS = [ ["paragraph", { text: "Every content block type, top to bottom, with each of its options. Use it to check the page after changing how blocks draw." }], @@ -109,6 +127,8 @@ const ALL_BLOCKS = [ ["subheading", { text: "Images" }], ["image", { media: IMAGE, alt: "Describe the picture here", text: "An image with a caption and alt text" }], ["image", { media: IMAGE, alt: "The same picture, linked", href: "/history" }], + ["subheading", { text: "Schedule" }], + SCHEDULE, ["subheading", { text: "Video" }], ["video", { href: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", text: "A YouTube video, with its own thumbnail" }], ["video", { href: "https://vimeo.com/76979871", media: IMAGE, text: "A Vimeo video with an uploaded still" }], @@ -354,7 +374,7 @@ tx(db, () => { { kind: "social", platform: "instagram", label: "@showcaseretreat", url: "https://instagram.com/showcaseretreat" }, ]); blocks("event", EVENT, "card", cardText("event")); - blocks("event", EVENT, "body", pageBody("event")); + blocks("event", EVENT, "body", [...pageBody("event"), ["heading", { text: "Schedule" }], SCHEDULE]); insert("events", { id: SERIES, diff --git a/server/src/shape.js b/server/src/shape.js index 5973156..179d71c 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -98,18 +98,39 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") { const itemRows = db .prepare( - `SELECT block_id, text, detail, url - FROM content_block_items - WHERE block_id IN (${placeholders(blockIds.length)}) - ORDER BY block_id, sort_order`, + `SELECT i.block_id, i.text, i.detail, i.url, + i.day, i.time, i.location, i.description, i.media, i.map, + p.id AS person_id, p.display_name AS person_name, + p.photo AS person_photo, p.tagline AS person_tagline + FROM content_block_items i + LEFT JOIN people p ON p.id = i.person_id AND p.is_published = 1 + WHERE i.block_id IN (${placeholders(blockIds.length)}) + ORDER BY i.block_id, i.sort_order`, ) .all(...blockIds); + // The schedule fields are null on a list or link-row item; they + // ride along anyway rather than branching on the block's type. + // An unpublished person comes back as no person. for (const row of itemRows) { byId.get(row.block_id)?.items.push({ text: row.text, detail: row.detail, url: row.url, + day: row.day, + time: row.time, + location: row.location, + description: row.description, + media: row.media, + map: row.map, + person: row.person_id + ? { + id: row.person_id, + name: row.person_name, + photo: row.person_photo, + tagline: row.person_tagline, + } + : null, }); } diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx index d94e4b9..959dcd3 100644 --- a/src/components/ContentBlocks.tsx +++ b/src/components/ContentBlocks.tsx @@ -19,6 +19,10 @@ image media, alt, text is the caption, href video href is the video, media a still, text the caption; click to play + schedule items as entries in day tabs (day, time, + text, detail, url, location, person, and + a fold-out of description, media, map); + text is an optional intro. ScheduleBlock divider nothing "Formatted" is InlineText.tsx: **bold**, *italic*, [text](url), @@ -33,6 +37,7 @@ import { blockMedia } from '../lib/media.ts' import type { ContentBlock } from '../lib/useContent.ts' import { Anchor, Inline, Paragraphs } from './InlineText.tsx' import VideoPlayer from './VideoPlayer.tsx' +import ScheduleBlock from './ScheduleBlock.tsx' const BODY = '#4a6b72' @@ -196,6 +201,10 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) { ) + case 'schedule': + if (!block.items?.length) return null + return + case 'divider': return
diff --git a/src/components/ScheduleBlock.tsx b/src/components/ScheduleBlock.tsx new file mode 100644 index 0000000..05b6b10 --- /dev/null +++ b/src/components/ScheduleBlock.tsx @@ -0,0 +1,270 @@ +/* ═══════════════════════════════════════════════════════════════ + SCHEDULE BLOCK + + The 'schedule' content block (034_schedule_block.sql): entries + in one tab per day, each a row of time, title, place and person, + folding out for the rest. + + Tabs are the entries' `day` values in the order they first + appear, so the admin's order is the page's. An entry with no day + joins an untitled group; a schedule of one day draws no tabs. The + tab whose name starts with today's weekday opens first ("Friday", + "Fri", "Friday, June 6"), so on the day of an event the visitor + lands on today; otherwise the first tab. + + A row folds out when it has anything more to show: a + description, a graphic, a map, or a person (their photo, tagline + and a link to their page). The map is Google's key-free embed of + the place typed in, with a link out to the full map. + + Tabs follow the ARIA tab pattern: arrow keys move between them. + ═══════════════════════════════════════════════════════════════ */ + +import { useId, useState, type KeyboardEvent } from 'react' +import { Link } from 'react-router-dom' + +import { personHref } from '../lib/hrefs.ts' +import { blockMedia, initials, personPhoto } from '../lib/media.ts' +import type { ContentBlockItem } from '../lib/useContent.ts' +import { Anchor, Paragraphs } from './InlineText.tsx' + +const BODY = '#4a6b72' +const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'] + +type Day = { name: string; entries: ContentBlockItem[] } + +function groupByDay(items: ContentBlockItem[]): Day[] { + const days: Day[] = [] + for (const item of items) { + const name = item.day?.trim() ?? '' + let day = days.find((d) => d.name === name) + if (!day) { + day = { name, entries: [] } + days.push(day) + } + day.entries.push(item) + } + return days +} + +/* The tab to open with: today's weekday if a tab starts with it (or + its three-letter form), else the first. */ +function todayIndex(days: Day[]): number { + const today = WEEKDAYS[new Date().getDay()] + const found = days.findIndex((day) => { + const name = day.name.toLowerCase() + return name.startsWith(today) || name.startsWith(today.slice(0, 3)) + }) + return found >= 0 ? found : 0 +} + +const mapEmbed = (place: string) => + `https://maps.google.com/maps?q=${encodeURIComponent(place)}&output=embed` +const mapLink = (place: string) => + `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(place)}` + +function Avatar({ person, size }: { person: NonNullable; size: string }) { + const [failed, setFailed] = useState(false) + const src = personPhoto(person.photo) + return src && !failed ? ( + setFailed(true)} className={`${size} shrink-0 rounded-full object-cover`} /> + ) : ( + + ) +} + +function Entry({ entry, accent }: { entry: ContentBlockItem; accent: string }) { + const [open, setOpen] = useState(false) + const panelId = useId() + const graphic = blockMedia(entry.media) + const place = entry.map?.trim() + const more = Boolean(entry.description || graphic || place || entry.person) + + const title = entry.url ? ( + + {entry.text} + + ) : ( + entry.text + ) + + return ( +
  • +
    +

    + {entry.time} +

    + +
    +

    {title}

    + {(entry.location || entry.person) && ( +

    + {entry.location && {entry.location}} + {entry.person && ( + + + {entry.person.name} + + )} +

    + )} + {entry.detail && ( +

    + {entry.detail} +

    + )} +
    + + {more && ( + + )} +
    + + {more && open && ( +
    + {entry.person && ( +
    + +
    + + {entry.person.name} + + {entry.person.tagline && ( +

    + {entry.person.tagline} +

    + )} +
    +
    + )} + + {entry.description && ( +
    + +
    + )} + + {graphic && } + + {place && ( +
    +