diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index 36d92c0..2134268 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -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`. 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. | +| 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`. | | 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-crud.js b/server/src/admin-crud.js index 9bd2723..18bfdc5 100644 --- a/server/src/admin-crud.js +++ b/server/src/admin-crud.js @@ -494,8 +494,6 @@ 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. diff --git a/server/src/admin-schema/columns.js b/server/src/admin-schema/columns.js index 3416e07..a25b0c2 100644 --- a/server/src/admin-schema/columns.js +++ b/server/src/admin-schema/columns.js @@ -196,8 +196,6 @@ 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: [ { @@ -222,26 +220,10 @@ 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"), - ], - }, ], }); diff --git a/server/src/migrations/087_schedule_tags.sql b/server/src/migrations/087_schedule_tags.sql deleted file mode 100644 index 78feba1..0000000 --- a/server/src/migrations/087_schedule_tags.sql +++ /dev/null @@ -1,28 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 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; diff --git a/server/src/seed-showcase.js b/server/src/seed-showcase.js index 07c8a77..d50303d 100644 --- a/server/src/seed-showcase.js +++ b/server/src/seed-showcase.js @@ -86,29 +86,24 @@ 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, - 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). */ + 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", tags: "showcase-youth,showcase-all" }, + { day: "Friday", start_time: "16:00", text: "Arrivals and check-in", location: "Front desk" }, { 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, tags: "showcase-youth", 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, 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, tags: "showcase-youth", 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, 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?] */ @@ -213,7 +208,7 @@ function insert(table, row) { } function blocks(ownerKind, ownerId, slot, list) { - list.forEach(([type, f, items = [], tags = []], order) => { + list.forEach(([type, f, items = []], order) => { const { lastInsertRowid } = insert("content_blocks", { owner_kind: ownerKind, owner_id: ownerId, @@ -226,7 +221,6 @@ 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 })); }); } diff --git a/server/src/shape.js b/server/src/shape.js index aee9313..dd9456e 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -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.tags, + i.description, i.media, i.media_alt, i.map, i.map_image, i.featured, p.id AS person_id, p.display_name AS person_name, p.photo AS person_photo, p.tagline AS person_tagline`; @@ -146,32 +146,6 @@ 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; } @@ -193,7 +167,6 @@ 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, diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx index 4d9299e..2c846d5 100644 --- a/src/components/ContentBlocks.tsx +++ b/src/components/ContentBlocks.tsx @@ -385,15 +385,7 @@ function Block({ case 'schedule': if (!block.items?.length) return null - return ( - - ) + return case 'people': { const picked = (block.items ?? []) diff --git a/src/components/ScheduleBlock.tsx b/src/components/ScheduleBlock.tsx index ef7a5a2..f57d1ac 100644 --- a/src/components/ScheduleBlock.tsx +++ b/src/components/ScheduleBlock.tsx @@ -26,12 +26,6 @@ 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). @@ -43,12 +37,12 @@ ═══════════════════════════════════════════════════════════════ */ import { CaretDown, Presentation, Star } from '@phosphor-icons/react' -import { Fragment, createContext, useContext, useId, useState, type KeyboardEvent, type ReactNode } from 'react' +import { Fragment, 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, ScheduleTag } from '../lib/useContent.ts' +import type { ContentBlockItem } from '../lib/useContent.ts' import { Anchor, Paragraphs } from './InlineText.tsx' import { withAlpha, accentText, readableOn } from '../lib/color.ts' import { useSmallImage } from '../lib/useSmallImage.ts' @@ -74,57 +68,6 @@ 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([]) - -/* 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 ( - - {shown.map((tag) => { - const color = tag.color || accent - return ( - - {tag.name} - - ) - })} - - ) -} - /* 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 { @@ -176,7 +119,6 @@ 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) @@ -254,11 +196,6 @@ function Entry({ entry, accent, sub = false }: { entry: ContentBlockItem; accent {entry.detail}

)} - {entry.tags?.length ? ( -
- -
- ) : null} {more && ( @@ -363,7 +300,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, tags: ScheduleTag[]): ReactNode { +function readingEntry(entry: ContentBlockItem, accent: string, key: number): ReactNode { if (entry.kind === 'heading') { return (
  • @@ -395,9 +332,6 @@ function readingEntry(entry: ContentBlockItem, accent: string, key: number, tags ))}

    {entry.detail &&

    {entry.detail}

    } - {entry.tags?.length ? ( -

    Tags: {tags.filter((tag) => entry.tags!.includes(tag.key)).map((tag) => tag.name).join(', ')}

    - ) : null} {entry.person?.tagline &&

    {entry.person.tagline}

    } {entry.description && } {graphic && {entry.media_alt} @@ -408,7 +342,7 @@ function readingEntry(entry: ContentBlockItem, accent: string, key: number, tags

    )} {entry.kind === 'block' && entry.items?.length ? ( -
      {entry.items.map((item, i) => readingEntry(item, accent, i, tags))}
    +
      {entry.items.map((item, i) => readingEntry(item, accent, i))}
    ) : null}
  • ) @@ -416,42 +350,27 @@ function readingEntry(entry: ContentBlockItem, accent: string, key: number, tags /* 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, - tags, - intro, - accent, -}: { - days: Day[] - tags: ScheduleTag[] - intro?: string | null - accent: string -}) { +function ReadingSchedule({ days, intro, accent }: { days: Day[]; intro?: string | null; accent: string }) { return (
    {intro && } {days.map((day, index) => (
    {days.length > 1 &&

    {day.name || 'Schedule'}

    } -
      {day.entries.map((entry, i) => readingEntry(entry, accent, i, tags))}
    +
      {day.entries.map((entry, i) => readingEntry(entry, accent, i))}
    ))}
    ) } -/* 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. */ @@ -463,24 +382,15 @@ export default function ScheduleBlock({ const reading = useReadingMode() if (days.length === 0) return null - if (reading) return - - 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] + if (reading) return + const current = days[Math.min(active, days.length - 1)] // Arrows move one tab and wrap; Home and End jump to the ends. const onKey = (e: KeyboardEvent) => { - const last = tabs.length - 1 + const last = days.length - 1 const next = - e.key === 'ArrowRight' ? (at + 1) % tabs.length - : e.key === 'ArrowLeft' ? (at + last) % tabs.length + e.key === 'ArrowRight' ? (active + 1) % days.length + : e.key === 'ArrowLeft' ? (active + last) % days.length : e.key === 'Home' ? 0 : e.key === 'End' ? last : null @@ -491,82 +401,67 @@ export default function ScheduleBlock({ } return ( - -
    - {intro && ( -
    - -
    - )} - - {presentHref && ( -
    - -
    - )} - - {tabs.length > 1 && ( -
    - {tabs.map((tab, index) => { - const selected = index === at - const color = tab.color || accent - return ( - - ) - })} -
    - )} - -
    1 ? 'tabpanel' : undefined} - aria-labelledby={tabs.length > 1 ? `${baseId}-tab-${at}` : undefined} - className="border border-brand/15 bg-surface" - > - {current.days.map((day, d) => ( - - {/* A tag's tab names each day it gathers from. */} - {current.tag && current.days.length > 1 && ( -

    - {day.name || 'Schedule'} -

    - )} -
      - {day.entries.map((entry, index) => ( - - ))} -
    -
    - ))} +
    + {intro && ( +
    +
    -
    - + )} + + {presentHref && ( +
    + +
    + )} + + {days.length > 1 && ( +
    + {days.map((day, index) => { + const selected = day === current + return ( + + ) + })} +
    + )} + +
      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) => ( + + ))} +
    +
    ) } diff --git a/src/components/admin/fields.tsx b/src/components/admin/fields.tsx index b80c2fc..3243c02 100644 --- a/src/components/admin/fields.tsx +++ b/src/components/admin/fields.tsx @@ -24,18 +24,7 @@ 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. `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. + saved as real input. In a repeater row, `when: { path, value }` shows a field only while another field of the row holds that value (or one of them, @@ -237,49 +226,8 @@ 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

    {empty ?? "Nothing to pick yet."}

    ; - 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 ( -
    - {options.map((o) => ( - - ))} -
    - ); -} - /* ── Field ───────────────────────────────────────────────────── */ export function Field({ field, value, row, options, error, onChange, onPatch }: any) { @@ -367,15 +315,6 @@ export function Field({ field, value, row, options, error, onChange, onPatch }: /> {helpText(field, row) ?? "Yes"} - ) : widget === "checklist" ? ( - ) : widget === "textarea" ? (