Schedule tags: a block's own tags, tag tabs, chips, a tag filter and tag slides

A schedule block gets its own tags (content_block_tags, migration 087):
a name, a color and whether it's a tab. Entries and sub-items pick them
from a checklist. Each tag is a tab after the days, gathering what it's
on from every day under the day's name; a tagged entry comes whole and
an untagged block brings only its tagged sub-items. Rows show their tags
as chips. The presentation can show only one tag's entries and adds a
slide per tag after the days.

Entries name a tag by a key the admin makes when the tag is added, so a
rename keeps them, since the block's rows are rewritten on every save.
For that the admin engine gets a function blank (fresh values for every
new row and copy, with a `seeded` column that doesn't count as input),
`lends` (a row's options for the collections nested in it) and a
checklist widget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-11-03 02:04:06 -06:00
parent 7885d10249
commit 71d58318b6
12 changed files with 539 additions and 122 deletions

View file

@ -182,7 +182,7 @@ also in `server/src/admin-schema/` and a CHECK):
| 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, schedule, table | **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/shared.ts`). |
| Content blocks → Schedule items → Type | (blank: normal entry), block, break, heading | **yes**, migration 086 | `SCHEDULE_KINDS` in `src/lib/adminSchema/shared.ts`; drawn by `ScheduleBlock.tsx` and `SchedulePresent.tsx` (which slides each kind gets). A block's sub-items are `content_block_subitems`. |
| Content blocks → Schedule items → Type | (blank: normal entry), block, break, heading | **yes**, migration 086 | `SCHEDULE_KINDS` in `src/lib/adminSchema/shared.ts`; drawn by `ScheduleBlock.tsx` and `SchedulePresent.tsx` (which slides each kind gets). A block's sub-items are `content_block_subitems`. A schedule's own tags (087) are `content_block_tags`, rows of the block typed in the admin (not a fixed list); entries name them by `tag_key`, made in the admin as the tag is added. |
| 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 |

View file

@ -494,6 +494,8 @@ function isBlankChildRow(child, raw) {
if (!raw || typeof raw !== "object") return true;
for (const column of child.columns) {
// A value the admin seeds every new row with (`seeded`), not input.
if (column.seeded) continue;
const value = raw[column.name];
if (value === undefined || value === null || value === "") continue;
// An unchecked box is the default state of a new row, not input.

View file

@ -196,6 +196,8 @@ export const blocksChild = (ownerKind) => ({
time("start_time"),
time("end_time"),
bool("featured"),
// The block's tags it has, by key, comma-separated (087).
text("tags"),
],
children: [
{
@ -220,10 +222,26 @@ export const blocksChild = (ownerKind) => ({
text("map"),
text("map_image"),
bool("featured"),
text("tags"),
],
},
],
},
{
// A schedule's own tags (087).
key: "tags",
table: "content_block_tags",
owner: { column: "block_id" },
order: "sort_order",
when: { column: "type", value: "schedule" },
columns: [
// Made by the admin as the row is added, so it isn't input.
text("tag_key", { required: true, seeded: true }),
text("name", { required: true }),
text("color"),
bool("no_tab"),
],
},
],
});

View file

@ -0,0 +1,28 @@
-- ═══════════════════════════════════════════════════════════════
-- 087 SCHEDULE TAGS
--
-- A schedule block's own tags, eg. Youth or Worship: entries and
-- sub-items are tagged with them, a tag can be a tab of its own
-- gathering every entry it's on (across the days), and the schedule
-- presentation can show only one tag's entries and a slide per tag.
--
-- These are the block's, not Data → Tags (070). The block's rows are
-- rewritten on every save, so entries name a tag by `tag_key` (made
-- in the admin when the tag is added, kept when it's renamed), not
-- by its row id. An entry's `tags` is its keys, comma-separated; a
-- key no tag has any more is skipped.
-- ═══════════════════════════════════════════════════════════════
CREATE TABLE content_block_tags (
id INTEGER PRIMARY KEY AUTOINCREMENT,
block_id INTEGER NOT NULL REFERENCES content_blocks (id) ON DELETE CASCADE,
sort_order INTEGER NOT NULL DEFAULT 0,
tag_key TEXT NOT NULL,
name TEXT NOT NULL,
color TEXT, -- null: the event's accent
no_tab INTEGER NOT NULL DEFAULT 0 CHECK (no_tab IN (0, 1)),
UNIQUE (block_id, tag_key)
) STRICT;
ALTER TABLE content_block_items ADD COLUMN tags TEXT;
ALTER TABLE content_block_subitems ADD COLUMN tags TEXT;

View file

@ -86,24 +86,29 @@ const PAST = "showcase-past-event";
plain entry, one with a location and person, one folding out with
a description, graphic and map, one linked, a heading, a featured
entry, a block with sub-items, a break, typed and picked times,
and one with no day (it lands in a tab of its own). */
tags (one a tab of its own in its color, one with No tab), 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", start_time: "16:00", text: "Arrivals and check-in", location: "Front desk" },
{ day: "Friday", start_time: "16:00", text: "Arrivals and check-in", location: "Front desk", tags: "showcase-youth,showcase-all" },
{ day: "Friday", kind: "heading", text: "Evening", detail: "A heading across the day" },
{ 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", map_image: "/uploads/showcase.jpg" },
{ day: "Saturday", start_time: "08:00", end_time: "09:00", kind: "break", text: "Breakfast", location: "Dining hall" },
{ day: "Saturday", start_time: "09:00", end_time: "10:30", kind: "block", text: "Workshops", location: "Classrooms", detail: "Pick one of three", items: [
{ start_time: "09:00", end_time: "09:45", text: "Leading worship", location: "Room A", person_id: "showcase-member-2", url: "/blog/content-block-showcase" },
{ start_time: "09:00", end_time: "09:45", text: "Speaking with confidence", location: "Room B", featured: 1, description: "A featured sub-item that folds out." },
{ start_time: "09:00", end_time: "09:45", text: "Speaking with confidence", location: "Room B", featured: 1, tags: "showcase-youth", description: "A featured sub-item that folds out." },
{ time: "After the first round", text: "Open questions", location: "Room C" },
] },
{ day: "Saturday", start_time: "19:00", featured: 1, text: "Talent night", location: "Main Hall", person_id: "showcase-member-3", description: "Sign up at the front desk by noon." },
{ day: "Saturday", start_time: "19:00", featured: 1, tags: "showcase-youth", 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" },
],
[
{ tag_key: "showcase-youth", name: "Youth", color: "#00748a" },
{ tag_key: "showcase-all", name: "Everyone", no_tab: 1 },
],
];
/* Every block type, for the blog showcase. [type, fields, items?] */
@ -208,7 +213,7 @@ function insert(table, row) {
}
function blocks(ownerKind, ownerId, slot, list) {
list.forEach(([type, f, items = []], order) => {
list.forEach(([type, f, items = [], tags = []], order) => {
const { lastInsertRowid } = insert("content_blocks", {
owner_kind: ownerKind,
owner_id: ownerId,
@ -221,6 +226,7 @@ function blocks(ownerKind, ownerId, slot, list) {
const entry = insert("content_block_items", { block_id: lastInsertRowid, sort_order: i, ...item });
subitems.forEach((sub, j) => insert("content_block_subitems", { item_id: entry.lastInsertRowid, sort_order: j, ...sub }));
});
tags.forEach((tag, i) => insert("content_block_tags", { block_id: lastInsertRowid, sort_order: i, ...tag }));
});
}

View file

@ -108,7 +108,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
const blockIds = [...byId.keys()];
const ENTRY_FIELDS = `i.text, i.detail, i.url, i.start_time, i.end_time, i.time, i.location,
i.description, i.media, i.media_alt, i.map, i.map_image, i.featured,
i.description, i.media, i.media_alt, i.map, i.map_image, i.featured, i.tags,
p.id AS person_id, p.display_name AS person_name,
p.photo AS person_photo, p.tagline AS person_tagline`;
@ -146,6 +146,32 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") {
for (const row of subRows) itemsById.get(row.item_id)?.items.push(scheduleEntry(row));
}
// A schedule's own tags (087), and each entry's cut to the ones
// the block still has.
const tagRows = db
.prepare(
`SELECT block_id, tag_key, name, color, no_tab
FROM content_block_tags
WHERE block_id IN (${placeholders(blockIds.length)})
ORDER BY block_id, sort_order`,
)
.all(...blockIds);
for (const row of tagRows) {
const block = byId.get(row.block_id);
if (!block) continue;
block.tags ??= [];
block.tags.push({ key: row.tag_key, name: row.name, color: row.color, tab: row.no_tab === 0 });
}
for (const block of byId.values()) {
if (block.type !== "schedule") continue;
const known = new Set((block.tags ??= []).map((tag) => tag.key));
const cut = (entry) => {
entry.tags = entry.tags.filter((key) => known.has(key));
entry.items?.forEach(cut);
};
block.items.forEach(cut);
}
return out;
}
@ -167,6 +193,7 @@ function scheduleEntry(row) {
map: row.map,
map_image: row.map_image,
featured: row.featured === 1,
tags: row.tags ? row.tags.split(",").filter(Boolean) : [],
person: row.person_id
? {
id: row.person_id,

View file

@ -385,7 +385,15 @@ function Block({
case 'schedule':
if (!block.items?.length) return null
return <ScheduleBlock items={block.items} intro={block.text} accent={accent} presentHref={presentHref} />
return (
<ScheduleBlock
items={block.items}
tags={block.tags}
intro={block.text}
accent={accent}
presentHref={presentHref}
/>
)
case 'people': {
const picked = (block.items ?? [])

View file

@ -26,6 +26,12 @@
across. The time shown is `time`, which the API has already made
from the picked times or the typed override.
Tags (087) are the block's own: an entry or sub-item shows its
tags as chips, and each tag (unless it's set No tab) is a tab
after the days, gathering what it's on from every day under the
day's name. A tagged entry comes whole; an untagged block comes
with only its tagged sub-items. A tag on nothing draws no tab.
On an event page a Present button opens the schedule as a
slideshow for a screen (SchedulePresent.tsx).
@ -37,12 +43,12 @@
═══════════════════════════════════════════════════════════════ */
import { CaretDown, Presentation, Star } from '@phosphor-icons/react'
import { Fragment, useId, useState, type KeyboardEvent, type ReactNode } from 'react'
import { Fragment, createContext, useContext, useId, useState, type KeyboardEvent, type ReactNode } from 'react'
import { Link } from 'react-router-dom'
import { personHref } from '../lib/hrefs.ts'
import { mediaUrl, initials } from '../lib/media.ts'
import type { ContentBlockItem } from '../lib/useContent.ts'
import type { ContentBlockItem, ScheduleTag } from '../lib/useContent.ts'
import { Anchor, Paragraphs } from './InlineText.tsx'
import { withAlpha, accentText, readableOn } from '../lib/color.ts'
import { useSmallImage } from '../lib/useSmallImage.ts'
@ -68,6 +74,57 @@ export function groupByDay(items: ContentBlockItem[]): Day[] {
return days
}
/* What a tag is on (087): a tagged entry whole, and an untagged
block with only its tagged sub-items. */
export function withTag(entries: ContentBlockItem[], key: string): ContentBlockItem[] {
return entries.flatMap((entry) => {
if (entry.tags?.includes(key)) return [entry]
if (entry.kind !== 'block') return []
const items = (entry.items ?? []).filter((item) => item.tags?.includes(key))
return items.length ? [{ ...entry, items }] : []
})
}
/* The days, each cut to what a tag is on, empty ones dropped. */
export const daysWithTag = (days: Day[], key: string): Day[] =>
days.map((day) => ({ name: day.name, entries: withTag(day.entries, key) })).filter((day) => day.entries.length)
/* The schedule's tags, for its rows' chips. */
export const ScheduleTags = createContext<ScheduleTag[]>([])
/* An entry's tags as chips, each in its tag's color (else the
accent). `className` sizes them. */
export function TagChips({
keys,
tags,
accent,
className = 'px-2 py-0.5 text-xs',
}: {
keys?: string[]
tags: ScheduleTag[]
accent: string
className?: string
}) {
const shown = tags.filter((tag) => keys?.includes(tag.key))
if (shown.length === 0) return null
return (
<span className="inline-flex flex-wrap gap-1.5">
{shown.map((tag) => {
const color = tag.color || accent
return (
<span
key={tag.key}
className={`font-semibold ${className}`}
style={{ background: withAlpha(color, 14), color: accentText(color) }}
>
{tag.name}
</span>
)
})}
</span>
)
}
/* 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 {
@ -119,6 +176,7 @@ export const featuredStyle = (accent: string) => ({
})
function Entry({ entry, accent, sub = false }: { entry: ContentBlockItem; accent: string; sub?: boolean }) {
const tags = useContext(ScheduleTags)
const [open, setOpen] = useState(false)
// Google's map loads only when asked for (Privacy page).
const [showMap, setShowMap] = useState(false)
@ -196,6 +254,11 @@ function Entry({ entry, accent, sub = false }: { entry: ContentBlockItem; accent
{entry.detail}
</p>
)}
{entry.tags?.length ? (
<div className="mt-2">
<TagChips keys={entry.tags} tags={tags} accent={accent} />
</div>
) : null}
</div>
{more && (
@ -300,7 +363,7 @@ function Entry({ entry, accent, sub = false }: { entry: ContentBlockItem; accent
}
/* One entry in reading mode, a block's sub-items in a list under it. */
function readingEntry(entry: ContentBlockItem, accent: string, key: number): ReactNode {
function readingEntry(entry: ContentBlockItem, accent: string, key: number, tags: ScheduleTag[]): ReactNode {
if (entry.kind === 'heading') {
return (
<li key={key}>
@ -332,6 +395,9 @@ function readingEntry(entry: ContentBlockItem, accent: string, key: number): Rea
))}
</p>
{entry.detail && <p>{entry.detail}</p>}
{entry.tags?.length ? (
<p>Tags: {tags.filter((tag) => entry.tags!.includes(tag.key)).map((tag) => tag.name).join(', ')}</p>
) : null}
{entry.person?.tagline && <p>{entry.person.tagline}</p>}
{entry.description && <Paragraphs text={entry.description} accent={accent} />}
{graphic && <img src={graphic} alt={entry.media_alt ?? ''} />}
@ -342,7 +408,7 @@ function readingEntry(entry: ContentBlockItem, accent: string, key: number): Rea
</p>
)}
{entry.kind === 'block' && entry.items?.length ? (
<ul>{entry.items.map((item, i) => readingEntry(item, accent, i))}</ul>
<ul>{entry.items.map((item, i) => readingEntry(item, accent, i, tags))}</ul>
) : null}
</li>
)
@ -350,27 +416,42 @@ function readingEntry(entry: ContentBlockItem, accent: string, key: number): Rea
/* Reading mode: every day, every entry and its fold-out, as text. A
day is an h4, under the page's h3 block headings (ContentBlocks). */
function ReadingSchedule({ days, intro, accent }: { days: Day[]; intro?: string | null; accent: string }) {
function ReadingSchedule({
days,
tags,
intro,
accent,
}: {
days: Day[]
tags: ScheduleTag[]
intro?: string | null
accent: string
}) {
return (
<div>
{intro && <Paragraphs text={intro} accent={accent} />}
{days.map((day, index) => (
<div key={day.name || index}>
{days.length > 1 && <h4>{day.name || 'Schedule'}</h4>}
<ul>{day.entries.map((entry, i) => readingEntry(entry, accent, i))}</ul>
<ul>{day.entries.map((entry, i) => readingEntry(entry, accent, i, tags))}</ul>
</div>
))}
</div>
)
}
/* A tab: a day, or a tag's entries from every day (087). */
type Tab = { label: string; days: Day[]; color?: string | null; tag?: boolean }
export default function ScheduleBlock({
items,
tags = [],
intro,
accent,
presentHref,
}: {
items: ContentBlockItem[]
tags?: ScheduleTag[]
intro?: string | null
accent: string
/** Where the Present button goes; no button without it. */
@ -382,15 +463,24 @@ export default function ScheduleBlock({
const reading = useReadingMode()
if (days.length === 0) return null
if (reading) return <ReadingSchedule days={days} intro={intro} accent={accent} />
const current = days[Math.min(active, days.length - 1)]
if (reading) return <ReadingSchedule days={days} tags={tags} intro={intro} accent={accent} />
const tabs: Tab[] = [
...days.map((day) => ({ label: day.name || 'Schedule', days: [day] })),
...tags
.filter((tag) => tag.tab)
.map((tag) => ({ label: tag.name, days: daysWithTag(days, tag.key), color: tag.color, tag: true }))
.filter((tab) => tab.days.length),
]
const at = Math.min(active, tabs.length - 1)
const current = tabs[at]
// Arrows move one tab and wrap; Home and End jump to the ends.
const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {
const last = days.length - 1
const last = tabs.length - 1
const next =
e.key === 'ArrowRight' ? (active + 1) % days.length
: e.key === 'ArrowLeft' ? (active + last) % days.length
e.key === 'ArrowRight' ? (at + 1) % tabs.length
: e.key === 'ArrowLeft' ? (at + last) % tabs.length
: e.key === 'Home' ? 0
: e.key === 'End' ? last
: null
@ -401,67 +491,82 @@ export default function ScheduleBlock({
}
return (
<div className="space-y-4">
{intro && (
<div className="space-y-3 leading-relaxed" style={{ color: BODY }}>
<Paragraphs text={intro} accent={accent} />
</div>
)}
<ScheduleTags.Provider value={tags}>
<div className="space-y-4">
{intro && (
<div className="space-y-3 leading-relaxed" style={{ color: BODY }}>
<Paragraphs text={intro} accent={accent} />
</div>
)}
{presentHref && (
<div className="flex justify-end">
<Link
to={presentHref}
target="_blank"
className="btn inline-flex items-center gap-2 border px-4 py-2 text-sm transition-colors hover:bg-tint"
style={{ borderColor: `${withAlpha(accent, 33)}`, color: accentText(accent) }}
>
<Presentation aria-hidden="true" weight="bold" className="h-4 w-4" />
Present
<span className="sr-only">(opens in a new tab)</span>
</Link>
</div>
)}
{presentHref && (
<div className="flex justify-end">
<Link
to={presentHref}
target="_blank"
className="btn inline-flex items-center gap-2 border px-4 py-2 text-sm transition-colors hover:bg-tint"
style={{ borderColor: `${withAlpha(accent, 33)}`, color: accentText(accent) }}
>
<Presentation aria-hidden="true" weight="bold" className="h-4 w-4" />
Present
<span className="sr-only">(opens in a new tab)</span>
</Link>
</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="btn border px-5 py-2 text-sm transition-colors"
style={
selected
? { background: accent, borderColor: accent, color: readableOn(accent) }
: { borderColor: `${withAlpha(accent, 33)}`, color: accentText(accent) }
}
>
{day.name || 'Schedule'}
</button>
)
})}
</div>
)}
{tabs.length > 1 && (
<div role="tablist" aria-label="Days and tags" className="flex flex-wrap gap-2">
{tabs.map((tab, index) => {
const selected = index === at
const color = tab.color || accent
return (
<button
key={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="btn border px-5 py-2 text-sm transition-colors"
style={
selected
? { background: color, borderColor: color, color: readableOn(color) }
: { borderColor: `${withAlpha(color, 33)}`, color: accentText(color) }
}
>
{tab.label}
</button>
)
})}
</div>
)}
<ul
id={`${baseId}-panel`}
role={days.length > 1 ? 'tabpanel' : undefined}
aria-labelledby={days.length > 1 ? `${baseId}-tab-${days.indexOf(current)}` : undefined}
className="border border-brand/15 bg-surface"
>
{current.entries.map((entry, index) => (
<Entry key={`${current.name}-${index}`} entry={entry} accent={accent} />
))}
</ul>
</div>
<div
id={`${baseId}-panel`}
role={tabs.length > 1 ? 'tabpanel' : undefined}
aria-labelledby={tabs.length > 1 ? `${baseId}-tab-${at}` : undefined}
className="border border-brand/15 bg-surface"
>
{current.days.map((day, d) => (
<Fragment key={`${at}-${d}`}>
{/* A tag's tab names each day it gathers from. */}
{current.tag && current.days.length > 1 && (
<p className="border-b border-brand/15 bg-tint px-5 py-2 text-sm font-bold text-ink">
{day.name || 'Schedule'}
</p>
)}
<ul>
{day.entries.map((entry, index) => (
<Entry key={`${at}-${d}-${index}`} entry={entry} accent={accent} />
))}
</ul>
</Fragment>
))}
</div>
</div>
</ScheduleTags.Provider>
)
}

View file

@ -24,7 +24,18 @@
server doesn't also declare as a column default. If you give a
blank row a starting value here, add the matching default: to
that column in the server's admin-schema.js or the row will be
saved as real input.
saved as real input. `blank` can be a function instead, for a
value made fresh for every new row and every copy (a schedule
tag's key); mark that column `seeded` on the server so a row with
only that in it still counts as blank.
`lends: (row) => ({ name: [{ id, label }] })` on a collection gives
the collections nested in each row (at any depth) more options,
made from that row: a schedule block lends its tags to its
entries and their sub-items.
`widget: "checklist"` is a checkbox per option of `optionsFrom`,
saved as the picked ids, comma-separated, in the options' order.
In a repeater row, `when: { path, value }` shows a field only
while another field of the row holds that value (or one of them,
@ -226,8 +237,49 @@ function withoutIds(value) {
return copy;
}
/* A new row, and the fresh values a function `blank` gives every
new row (a copy keeps the rest of what it copies). */
const newRow = (spec) => (typeof spec.blank === "function" ? spec.blank() : { ...spec.blank });
const seeded = (spec) => (typeof spec.blank === "function" ? spec.blank() : {});
const helpText = (field, row) => (typeof field.help === "function" ? field.help(row) : field.help);
/* `widget: "checklist"`: the picked ids, comma-separated. An id no
option has any more is dropped at the next change. */
function Checklist({ id, options, value, disabled, empty, onChange }: {
id: string
options: { id: string; label: string }[]
value?: string | null
disabled?: boolean
empty?: string
onChange: (value: string) => void
}) {
const picked = new Set((value ?? "").split(",").filter(Boolean));
if (options.length === 0) return <p id={id} className="text-sm text-muted">{empty ?? "Nothing to pick yet."}</p>;
const toggle = (key: string) => {
const next = new Set(picked);
if (next.has(key)) next.delete(key);
else next.add(key);
onChange(options.filter((o) => next.has(o.id)).map((o) => o.id).join(","));
};
return (
<div id={id} role="group" className="flex flex-wrap gap-x-4 gap-y-1.5">
{options.map((o) => (
<label key={o.id} className="flex items-center gap-2 text-sm text-body">
<input
type="checkbox"
checked={picked.has(o.id)}
disabled={disabled}
onChange={() => toggle(o.id)}
className="h-4 w-4 border-muted/40 text-link focus:ring-brand/40 disabled:opacity-50"
/>
{o.label}
</label>
))}
</div>
);
}
/* ── Field ───────────────────────────────────────────────────── */
export function Field({ field, value, row, options, error, onChange, onPatch }: any) {
@ -315,6 +367,15 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
/>
{helpText(field, row) ?? "Yes"}
</label>
) : widget === "checklist" ? (
<Checklist
id={id}
options={options?.[field.optionsFrom] ?? []}
value={value}
disabled={locked}
empty={field.emptyNote}
onChange={onChange}
/>
) : widget === "textarea" ? (
<textarea
{...common}
@ -558,7 +619,7 @@ export function Repeater({
const add = () => {
setOpen((prev) => new Set(prev).add(list.length));
onChange([...list, { ...spec.blank }]);
onChange([...list, newRow(spec)]);
};
/* A row placed at `at`, pushing everything from there down one,
@ -714,13 +775,13 @@ export function Repeater({
</IconButton>
<IconButton
label="Insert a new one below"
onClick={() => insertAt(index + 1, { ...spec.blank })}
onClick={() => insertAt(index + 1, newRow(spec))}
>
<Plus size={14} weight="bold" aria-hidden="true" />
</IconButton>
<IconButton
label="Duplicate"
onClick={() => insertAt(index + 1, withoutIds(row))}
onClick={() => insertAt(index + 1, { ...withoutIds(row), ...seeded(spec) })}
>
<Copy size={14} weight="bold" aria-hidden="true" />
</IconButton>
@ -760,7 +821,7 @@ export function Repeater({
<Repeater
spec={nested}
rows={row[nested.key]}
options={options}
options={spec.lends ? { ...options, ...spec.lends(row) } : options}
errors={errors}
errorPrefix={`${errorPrefix}${index}.${nested.key}.`}
parentRow={row}

View file

@ -402,6 +402,17 @@ export const wordFields = (prefix: string, label: string, when?: any) => [
{ path: `${prefix}word_seconds`, label: label ? `${label}seconds per word` : "Seconds per word", widget: "number", help: "1 to 20. Default: the site's", when },
];
/* An entry's or sub-item's tags (087): the block's, lent by
blocksChild. */
const TAGS_FIELD = {
path: "tags",
label: "Tags",
widget: "checklist",
optionsFrom: "scheduleTags",
full: true,
emptyNote: "No tags yet: add them under the block's Tags.",
};
/* A block entry's sub-item (086): an entry's fields, under its
block's day. */
const SUB_ITEM_FIELDS = [
@ -437,6 +448,7 @@ const SUB_ITEM_FIELDS = [
help: "Optional: your own map, shown in place of the Google map and as a slide when presented",
},
{ path: "featured", label: "Featured", widget: "checkbox", help: "Makes it stand out" },
TAGS_FIELD,
];
export const blocksChild = {
@ -536,7 +548,27 @@ export const blocksChild = {
},
...wordFields("", "", { path: "type", value: ["heading", "subheading", "paragraph", "callout", "quote"] }),
],
// A schedule's tags, for its entries' and sub-items' Tags (087).
lends: (row) => ({
scheduleTags: (row.tags ?? [])
.filter((tag) => tag.name?.trim())
.map((tag) => ({ id: tag.tag_key, label: tag.name })),
}),
children: [
{
key: "tags",
label: "Tags",
addLabel: "Add tag",
note: "Tag entries with these, eg. Youth or Worship. Each tag is a tab of its own gathering the entries it's on, and can be shown alone or as a slide when the schedule is presented.",
when: { path: "type", value: "schedule" },
title: (row) => row.name || "New tag",
blank: () => ({ tag_key: crypto.randomUUID().slice(0, 8) }),
fields: [
{ path: "name", label: "Name", required: true, help: "eg. Youth" },
{ path: "color", label: "Color", widget: "color", help: "Default: the event's color" },
{ path: "no_tab", label: "No tab", widget: "checkbox", help: "Leave it out of the tabs (it still shows on entries)" },
],
},
{
key: "items",
label: "Items",
@ -653,6 +685,7 @@ export const blocksChild = {
when: SCHEDULE_ENTRY,
},
{ path: "featured", label: "Featured", widget: "checkbox", help: "Makes the row stand out", when: SCHEDULE_ENTRY },
{ ...TAGS_FIELD, when: SCHEDULE_ENTRY },
],
children: [
{

View file

@ -55,8 +55,13 @@ export type ContentBlock = {
/** A video block's WebVTT file, for an uploaded video (066). */
captions?: string | null
items?: ContentBlockItem[]
/** A schedule's own tags (087). */
tags?: ScheduleTag[]
}
/** A schedule's tag (087). `tab` is whether it gets a tab of its own. */
export type ScheduleTag = { key: string; name: string; color?: string | null; tab: boolean }
/** A list, link-row or schedule entry. The schedule fields are
* empty on the other two (034_schedule_block.sql). */
export type ContentBlockItem = {
@ -82,6 +87,8 @@ export type ContentBlockItem = {
featured?: boolean
/** A block entry's sub-items. */
items?: ContentBlockItem[]
/** Its block's tags it has, by key (087). */
tags?: string[]
}
export type Link = {

View file

@ -18,21 +18,35 @@
the spotlight, graphic and map slides an entry does
graphic an entry's graphic, full screen
map an entry's own map image (069), full screen
tag after the days: each of the schedule's tags (087)
and everything it's on, under each day's name
A heading (086) is only a line on the overview; a break gets no
spotlight.
spotlight. "Only entries tagged" (`tag=<key>`) cuts every slide
to what one tag is on, eg. for a screen outside the youth room.
Keys while playing: arrows step, Space pauses, Escape leaves full
screen (the browser's), S goes back to the setup.
═══════════════════════════════════════════════════════════════ */
import { ArrowsOut, CaretLeft, CaretRight, Gear, Pause, Play } from '@phosphor-icons/react'
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import { useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import { useParams, useSearchParams } from 'react-router-dom'
import PageState from '../components/PageState.tsx'
import { Avatar, FeaturedStar, featuredStyle, groupByDay, mapAlt, type Day } from '../components/ScheduleBlock.tsx'
import {
Avatar,
FeaturedStar,
ScheduleTags,
TagChips,
daysWithTag,
featuredStyle,
groupByDay,
mapAlt,
withTag,
type Day,
} from '../components/ScheduleBlock.tsx'
import { Paragraphs } from '../components/InlineText.tsx'
import { useEvent, type ContentBlockItem } from '../lib/useContent.ts'
import { useEvent, type ContentBlockItem, type ScheduleTag } from '../lib/useContent.ts'
import { mediaUrl } from '../lib/media.ts'
import { BRAND, accentText, readableOn, withAlpha } from '../lib/color.ts'
import { documentTitle } from '../lib/site.ts'
@ -45,6 +59,7 @@ const KINDS = [
{ key: 'block', label: 'Blocks', help: 'A block and the things in it, before each gets a spotlight', seconds: 15 },
{ key: 'graphic', label: 'Graphics', help: "An entry's graphic, full screen", seconds: 10 },
{ key: 'map', label: 'Map images', help: "An entry's own map, full screen", seconds: 10 },
{ key: 'tag', label: 'Tag slides', help: "Each tag and everything it's on, after the days", seconds: 15 },
] as const
type Kind = (typeof KINDS)[number]['key']
@ -53,8 +68,17 @@ const ONE_COLUMN = 8
/* How long the controls stay up after the pointer last moved (ms). */
const CONTROLS_FOR = 2500
/* `parent` is a sub-item's block. */
type Slide = { kind: Kind; seconds: number; day: Day; entry?: ContentBlockItem; parent?: ContentBlockItem }
/* `parent` is a sub-item's block; a tag slide has its `tag` and the
`days` it gathers from. */
type Slide = {
kind: Kind
seconds: number
day: Day
entry?: ContentBlockItem
parent?: ContentBlockItem
tag?: ScheduleTag
days?: Day[]
}
/* An entry's key in the address: day index, a dot, entry index, and
for a sub-item another dot and its index. */
@ -73,20 +97,23 @@ function readSettings(params: URLSearchParams, days: Day[]) {
return [kind.key, Number.isFinite(value) && value > 0 ? value : 0]
}),
) as Record<Kind, number>
return { pickedDays: new Set(pickedDays), hidden, seconds }
return { pickedDays: new Set(pickedDays), hidden, seconds, only: params.get('tag') || null }
}
type Settings = ReturnType<typeof readSettings>
function buildSlides(days: Day[], { pickedDays, hidden, seconds }: Settings): Slide[] {
function buildSlides(days: Day[], tags: ScheduleTag[], { pickedDays, hidden, seconds, only }: Settings): Slide[] {
const slides: Slide[] = []
const kept: Day[] = []
days.forEach((all, d) => {
if (!pickedDays.has(d)) return
const entries = all.entries.flatMap((entry, e) => {
let entries = all.entries.flatMap((entry, e) => {
if (hidden.has(entryKey(d, e))) return []
if (entry.kind !== 'block') return [entry]
return [{ ...entry, items: (entry.items ?? []).filter((_, i) => !hidden.has(entryKey(d, e, i))) }]
})
if (only) entries = withTag(entries, only)
if (entries.length === 0) return
kept.push({ name: all.name, entries })
const day = { ...all, entries }
if (seconds.overview) slides.push({ kind: 'overview', seconds: seconds.overview, day })
@ -109,6 +136,14 @@ function buildSlides(days: Day[], { pickedDays, hidden, seconds }: Settings): Sl
media(entry)
}
})
if (seconds.tag) {
for (const tag of tags) {
if (only && tag.key !== only) continue
const tagDays = daysWithTag(kept, tag.key)
if (tagDays.length) slides.push({ kind: 'tag', seconds: seconds.tag, day: { name: '', entries: [] }, tag, days: tagDays })
}
}
return slides
}
@ -120,6 +155,7 @@ export default function SchedulePresent() {
const blockIndex = Number(params.get('block') ?? 0)
const schedule = event?.blocks?.filter((block) => block.type === 'schedule')[blockIndex]
const days = useMemo(() => groupByDay(schedule?.items ?? []), [schedule])
const tags = schedule?.tags ?? []
useEffect(() => {
if (event) document.title = documentTitle(`${event.title}: schedule`)
@ -156,16 +192,18 @@ export default function SchedulePresent() {
const settings = readSettings(params, days)
if (params.get('play') === '1') {
return (
<Player
title={event.title}
accent={accent}
slides={buildSlides(days, settings)}
onSetup={() => {
const next = new URLSearchParams(params)
next.delete('play')
setParams(next)
}}
/>
<ScheduleTags.Provider value={tags}>
<Player
title={event.title}
accent={accent}
slides={buildSlides(days, tags, settings)}
onSetup={() => {
const next = new URLSearchParams(params)
next.delete('play')
setParams(next)
}}
/>
</ScheduleTags.Provider>
)
}
return (
@ -174,6 +212,7 @@ export default function SchedulePresent() {
back={back}
accent={accent}
days={days}
tags={tags}
settings={settings}
onPlay={(next) => {
// Full screen needs the click itself, so it's asked for here.
@ -182,6 +221,7 @@ export default function SchedulePresent() {
if (next.pickedDays.size < days.length) out.set('days', [...next.pickedDays].sort((a, b) => a - b).join(','))
if (next.hidden.size) out.set('hide', [...next.hidden].join(','))
for (const kind of KINDS) out.set(kind.key, String(next.seconds[kind.key]))
if (next.only) out.set('tag', next.only)
out.set('play', '1')
setParams(out)
}}
@ -196,6 +236,7 @@ function Setup({
back,
accent,
days,
tags,
settings,
onPlay,
}: {
@ -203,13 +244,15 @@ function Setup({
back: string
accent: string
days: Day[]
tags: ScheduleTag[]
settings: Settings
onPlay: (settings: Settings) => void
}) {
const [pickedDays, setPickedDays] = useState(settings.pickedDays)
const [hidden, setHidden] = useState(settings.hidden)
const [seconds, setSeconds] = useState(settings.seconds)
const count = buildSlides(days, { pickedDays, hidden, seconds }).length
const [only, setOnly] = useState(settings.only)
const count = buildSlides(days, tags, { pickedDays, hidden, seconds, only }).length
const toggle = <T,>(set: Set<T>, value: T) => {
const next = new Set(set)
@ -260,6 +303,30 @@ function Setup({
<p className="mt-2 text-sm text-muted">0 leaves that kind of slide out.</p>
</section>
{tags.length > 0 && (
<section>
<h2 className="mb-4 text-2xl font-bold text-ink">Tags</h2>
<label className="flex flex-wrap items-center gap-4 bg-raised p-4 shadow-sm">
<span className="flex-1">
<span className="block font-semibold text-ink">Only entries tagged</span>
<span className="text-sm text-muted">Every slide shows only what this tag is on, eg. for one room's screen</span>
</span>
<select
value={only ?? ''}
onChange={(e) => setOnly(e.target.value || null)}
className="border border-muted/25 bg-surface px-2 py-1"
>
<option value="">Default: every entry</option>
{tags.map((tag) => (
<option key={tag.key} value={tag.key}>
{tag.name}
</option>
))}
</select>
</label>
</section>
)}
<section>
<h2 className="mb-4 text-2xl font-bold text-ink">Days and entries</h2>
<div className="space-y-6">
@ -305,7 +372,7 @@ function Setup({
<button
type="button"
disabled={count === 0}
onClick={() => onPlay({ pickedDays, hidden, seconds })}
onClick={() => onPlay({ pickedDays, hidden, seconds, only })}
className="btn inline-flex items-center gap-2 px-6 py-3 disabled:opacity-50"
style={{ background: accent, color: readableOn(accent) }}
>
@ -516,10 +583,36 @@ function Rise({ order = 0, from = 'below', className = '', children }: {
)
}
/* An overview's rows: each entry, a block's sub-items under it.
`start` is the first row's place in the slide's entrance. */
function OverviewEntries({ entries, accent, start = 1 }: { entries: ContentBlockItem[]; accent: string; start?: number }) {
return (
<>
{entries.map((entry, i) => (
<li key={i} className="even:bg-tint-soft/60" style={entry.featured ? featuredStyle(accent) : undefined}>
<Rise order={start + i} from="left">
<OverviewLine entry={entry} accent={accent} />
{entry.kind === 'block' && entry.items?.length ? (
<ul className="ml-[14vw] pb-[1vh]">
{entry.items.map((item, j) => (
<li key={j} style={item.featured ? featuredStyle(accent) : undefined}>
<OverviewLine entry={item} accent={accent} sub />
</li>
))}
</ul>
) : null}
</Rise>
</li>
))}
</>
)
}
/* One line of the day overview: an entry, or (`sub`) one of a
block's sub-items under it. A heading is a label; a break is
quieter. */
function OverviewLine({ entry, accent, sub = false }: { entry: ContentBlockItem; accent: string; sub?: boolean }) {
const tags = useContext(ScheduleTags)
const color = accentText(accent)
if (entry.kind === 'heading') {
return (
@ -553,10 +646,11 @@ function OverviewLine({ entry, accent, sub = false }: { entry: ContentBlockItem;
)}
{entry.text}
</span>
{(entry.location || entry.person) && (
<span className="mt-1 flex flex-wrap items-center gap-x-[1.5vw] text-[clamp(0.9rem,1.4vw,1.8rem)] text-muted">
{(entry.location || entry.person || entry.tags?.length) && (
<span className="mt-1 flex flex-wrap items-center gap-x-[1.5vw] gap-y-1 text-[clamp(0.9rem,1.4vw,1.8rem)] text-muted">
{entry.location && <span>{entry.location}</span>}
{entry.person && <span>{entry.person.name}</span>}
<TagChips keys={entry.tags} tags={tags} accent={accent} className="px-[0.6vw] py-[0.2vh] text-[0.8em]" />
</span>
)}
</span>
@ -565,6 +659,7 @@ function OverviewLine({ entry, accent, sub = false }: { entry: ContentBlockItem;
}
function SlideView({ slide, accent }: { slide: Slide; accent: string }) {
const tags = useContext(ScheduleTags)
const color = accentText(accent)
if (slide.kind === 'overview') {
@ -578,22 +673,42 @@ function SlideView({ slide, accent }: { slide: Slide; accent: string }) {
</h1>
</Rise>
<ul className={`grid min-h-0 flex-1 content-start gap-x-[4vw] ${two ? 'grid-cols-2' : 'grid-cols-1'}`}>
{entries.map((entry, i) => (
<li key={i} className="even:bg-tint-soft/60" style={entry.featured ? featuredStyle(accent) : undefined}>
<Rise order={i + 1} from="left">
<OverviewLine entry={entry} accent={accent} />
{entry.kind === 'block' && entry.items?.length ? (
<ul className="ml-[14vw] pb-[1vh]">
{entry.items.map((item, j) => (
<li key={j} style={item.featured ? featuredStyle(accent) : undefined}>
<OverviewLine entry={item} accent={accent} sub />
</li>
))}
</ul>
) : null}
</Rise>
</li>
))}
<OverviewEntries entries={entries} accent={accent} />
</ul>
</div>
)
}
if (slide.kind === 'tag') {
const tag = slide.tag!
const tagDays = slide.days ?? []
const tagColor = tag.color || accent
const two = tagDays.reduce((n, day) => n + 1 + lineCount(day.entries), 0) > ONE_COLUMN
let order = 1
return (
<div className="flex h-full flex-col">
<Rise>
<h1 className="mb-[3vh] text-[clamp(2rem,5vw,6rem)] font-bold leading-none" style={{ color: accentText(tagColor) }}>
{tag.name}
</h1>
</Rise>
<ul className={`grid min-h-0 flex-1 content-start gap-x-[4vw] ${two ? 'grid-cols-2' : 'grid-cols-1'}`}>
{tagDays.map((day, d) => {
const start = order
order += day.entries.length + 1
return (
<li key={d}>
{day.name && (
<Rise order={start} from="left">
<p className="pt-[1.5vh] pb-[0.5vh] text-[clamp(1rem,1.8vw,2.4rem)] font-bold text-ink">{day.name}</p>
</Rise>
)}
<ul>
<OverviewEntries entries={day.entries} accent={accent} start={start + 1} />
</ul>
</li>
)
})}
</ul>
</div>
)
@ -714,6 +829,13 @@ function SlideView({ slide, accent }: { slide: Slide; accent: string }) {
{entry.text}
</h1>
</Rise>
{entry.tags?.length ? (
<Rise order={2} from="right">
<p className="mt-[2vh]">
<TagChips keys={entry.tags} tags={tags} accent={accent} className="px-[1vw] py-[0.4vh] text-[clamp(0.9rem,1.6vw,2rem)]" />
</p>
</Rise>
) : null}
{entry.location && (
<Rise order={2} from="right">
<p className="mt-[2vh] text-[clamp(1.2rem,2.4vw,3rem)] text-body">{entry.location}</p>