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 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-27 21:12:47 -05:00
parent d6477b6d30
commit 71a470b66f
10 changed files with 556 additions and 29 deletions

View file

@ -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 }) {
</figure>
)
case 'schedule':
if (!block.items?.length) return null
return <ScheduleBlock items={block.items} intro={block.text} accent={accent} />
case 'divider':
return <hr className="border-0 h-px" style={{ background: accent, opacity: 0.3 }} />

View file

@ -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<ContentBlockItem['person']>; size: string }) {
const [failed, setFailed] = useState(false)
const src = personPhoto(person.photo)
return src && !failed ? (
<img src={src} alt="" onError={() => setFailed(true)} className={`${size} shrink-0 rounded-full object-cover`} />
) : (
<span
aria-hidden="true"
className={`${size} flex shrink-0 items-center justify-center rounded-full bg-[#eef9fb] text-xs font-bold text-[#138ba0]`}
>
{initials(person.name)}
</span>
)
}
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 ? (
<Anchor href={entry.url} className="underline-offset-2 hover:underline" style={{ color: accent }}>
{entry.text}
</Anchor>
) : (
entry.text
)
return (
<li className="border-b border-[#138ba0]/10 last:border-b-0">
<div className="flex gap-4 py-4 sm:gap-6">
<p className="w-24 shrink-0 pt-0.5 text-sm font-semibold sm:w-32" style={{ color: accent }}>
{entry.time}
</p>
<div className="min-w-0 flex-1">
<p className="font-semibold text-[#26454c]">{title}</p>
{(entry.location || entry.person) && (
<p className="mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm" style={{ color: BODY }}>
{entry.location && <span>{entry.location}</span>}
{entry.person && (
<span className="inline-flex items-center gap-2">
<Avatar person={entry.person} size="h-6 w-6" />
{entry.person.name}
</span>
)}
</p>
)}
{entry.detail && (
<p className="mt-1 text-sm" style={{ color: BODY }}>
{entry.detail}
</p>
)}
</div>
{more && (
<button
type="button"
onClick={() => setOpen((o) => !o)}
aria-expanded={open}
aria-controls={panelId}
aria-label={open ? `Less about ${entry.text}` : `More about ${entry.text}`}
className="h-8 w-8 shrink-0 rounded-full border text-sm transition-colors hover:bg-[#eef9fb]"
style={{ borderColor: `${accent}55`, color: accent }}
>
<span aria-hidden="true" className={`inline-block transition-transform ${open ? 'rotate-180' : ''}`}>
▾
</span>
</button>
)}
</div>
{more && open && (
<div id={panelId} className="mb-5 space-y-5 rounded-2xl bg-[#f6fbfc] p-5 sm:ml-38">
{entry.person && (
<div className="flex items-center gap-4">
<Avatar person={entry.person} size="h-16 w-16" />
<div>
<Link
to={personHref(entry.person.id)}
className="font-semibold hover:underline"
style={{ color: accent }}
>
{entry.person.name}
</Link>
{entry.person.tagline && (
<p className="text-sm" style={{ color: BODY }}>
{entry.person.tagline}
</p>
)}
</div>
</div>
)}
{entry.description && (
<div className="space-y-3 leading-relaxed" style={{ color: BODY }}>
<Paragraphs text={entry.description} accent={accent} />
</div>
)}
{graphic && <img src={graphic} alt="" loading="lazy" className="w-full rounded-lg" />}
{place && (
<div>
<iframe
src={mapEmbed(place)}
title={`Map: ${place}`}
loading="lazy"
referrerPolicy="no-referrer-when-downgrade"
className="aspect-video w-full rounded-lg border-0"
/>
<a
href={mapLink(place)}
target="_blank"
rel="noreferrer"
className="mt-2 inline-block text-sm underline"
style={{ color: accent }}
>
Open in Google Maps
</a>
</div>
)}
</div>
)}
</li>
)
}
export default function ScheduleBlock({
items,
intro,
accent,
}: {
items: ContentBlockItem[]
intro?: string | null
accent: string
}) {
const days = groupByDay(items)
const [active, setActive] = useState(() => todayIndex(days))
const baseId = useId()
if (days.length === 0) return null
const current = days[Math.min(active, days.length - 1)]
const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {
const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0
if (!step) return
e.preventDefault()
const next = (active + step + days.length) % days.length
setActive(next)
document.getElementById(`${baseId}-tab-${next}`)?.focus()
}
return (
<div className="space-y-4">
{intro && (
<div className="space-y-3 leading-relaxed" style={{ color: BODY }}>
<Paragraphs text={intro} accent={accent} />
</div>
)}
{days.length > 1 && (
<div role="tablist" aria-label="Days" className="flex flex-wrap gap-2">
{days.map((day, index) => {
const selected = day === current
return (
<button
key={day.name || index}
id={`${baseId}-tab-${index}`}
type="button"
role="tab"
aria-selected={selected}
aria-controls={`${baseId}-panel`}
tabIndex={selected ? 0 : -1}
onClick={() => setActive(index)}
onKeyDown={onKey}
className="rounded-full border px-5 py-2 text-sm font-semibold transition-colors"
style={
selected
? { background: accent, borderColor: accent, color: '#ffffff' }
: { borderColor: `${accent}55`, color: accent }
}
>
{day.name || 'Schedule'}
</button>
)
})}
</div>
)}
<ul
id={`${baseId}-panel`}
role={days.length > 1 ? 'tabpanel' : undefined}
aria-labelledby={days.length > 1 ? `${baseId}-tab-${days.indexOf(current)}` : undefined}
className="rounded-2xl border border-[#138ba0]/15 bg-white px-5"
>
{current.entries.map((entry, index) => (
<Entry key={`${current.name}-${index}`} entry={entry} accent={accent} />
))}
</ul>
</div>
)
}

View file

@ -32,12 +32,17 @@
can't keep a value for a choice it no longer makes: a featured
card switched from "record" to "link" drops its record.
`when: { scope: "parent", path, value }` looks at the row this
collection belongs to instead: a schedule entry shows its day and
time only while the block above it is a schedule.
A nested collection takes `when` the same way, and one that goes
hidden is emptied: a list block turned into a paragraph drops its
items.
`help` may be a function of the row, for help that depends on
another field (a content block's type says what its text is).
`help` and `label` may be functions of the row, for wording that
depends on another field (a content block's type says what its
text is).
`preview` on a collection names an entry in PREVIEWS below; each
open row then shows how it will look on the site, drawn by the
@ -78,7 +83,24 @@ import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
/* Live previews a collection can name with `preview`. Each gets the
row as the form holds it, which is the API's shape. */
const PREVIEWS = {
contentBlock: (row) => <ContentBlocks blocks={[row]} />,
// The form holds an entry's person as person_id; the renderer wants
// the person, so it's looked up in the select options (a name, no
// photo: the options carry no more).
contentBlock: (row, options) => (
<ContentBlocks
blocks={[
{
...row,
items: (row.items ?? []).map((item) => {
const person = item.person_id
? options?.people?.find((p) => p.id === item.person_id)
: null;
return { ...item, person: person ? { id: person.id, name: person.label } : null };
}),
},
]}
/>
),
};
const input =
@ -118,25 +140,33 @@ export function setPath(object, path, value) {
/* ── Conditional fields ──────────────────────────────────────── */
export function fieldShown(field, row) {
export function fieldShown(field, row, parent?) {
if (!field.when) return true;
const want = Array.isArray(field.when.value) ? field.when.value : [field.when.value];
return want.includes(row?.[field.when.path]);
const source = field.when.scope === "parent" ? parent : row;
return want.includes(source?.[field.when.path]);
}
/* A row after an edit, with any field the edit hid cleared. "" is
the engine's deliberate clear, so it saves as NULL. */
function withHiddenCleared(spec, row) {
function withHiddenCleared(spec, row, parent?) {
let next = row;
for (const field of spec.fields) {
const value = next[field.path];
if (!fieldShown(field, next) && value != null && value !== "") {
if (!fieldShown(field, next, parent) && value != null && value !== "") {
next = { ...next, [field.path]: "" };
}
}
for (const nested of spec.children ?? []) {
if (!fieldShown(nested, next) && next[nested.key]?.length) {
const rows = next[nested.key];
if (!rows?.length) continue;
if (!fieldShown(nested, next, parent)) {
next = { ...next, [nested.key]: [] };
} else {
// Its rows may have fields that follow this row (scope
// "parent"), which this edit may just have hidden.
const cleared = rows.map((child) => withHiddenCleared(nested, child, next));
if (cleared.some((child, i) => child !== rows[i])) next = { ...next, [nested.key]: cleared };
}
}
return next;
@ -197,7 +227,7 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
return (
<div className={field.full ? "sm:col-span-2" : ""}>
<label htmlFor={id} className="block text-sm font-medium text-[#26454c]">
{field.label}
{typeof field.label === "function" ? field.label(row) : field.label}
{field.required && !locked && <span className="ml-1 text-[#b3261e]">*</span>}
</label>
@ -357,6 +387,7 @@ export function Repeater({
errorPrefix,
onChange,
className = "mt-8",
parentRow = undefined,
}: any) {
const list = rows ?? [];
@ -382,7 +413,7 @@ export function Repeater({
const rowRefs = useRef<any[]>([]);
const update = (index, next) =>
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec, next) : row)));
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec, next, parentRow) : row)));
const move = (index, delta) => {
const target = index + delta;
@ -593,7 +624,7 @@ export function Repeater({
<>
<FieldGrid>
{spec.fields
.filter((field) => fieldShown(field, row))
.filter((field) => fieldShown(field, row, parentRow))
.map((field) => (
<Field
key={field.path}
@ -609,7 +640,7 @@ export function Repeater({
</FieldGrid>
{(spec.children ?? [])
.filter((nested) => fieldShown(nested, row))
.filter((nested) => fieldShown(nested, row, parentRow))
.map((nested) => (
<div key={nested.key} className="mt-4 border-t border-[#4a6b72]/15 pt-4">
<Repeater
@ -618,6 +649,7 @@ export function Repeater({
options={options}
errors={errors}
errorPrefix={`${errorPrefix}${index}.${nested.key}.`}
parentRow={row}
className=""
onChange={(value) => update(index, { ...row, [nested.key]: value })}
/>
@ -629,7 +661,7 @@ export function Repeater({
<p className="mb-3 text-xs font-semibold uppercase tracking-wider text-[#4a6b72]/70">
Preview
</p>
{PREVIEWS[spec.preview](row)}
{PREVIEWS[spec.preview](row, options)}
</div>
)}
</>