diff --git a/server/src/shape.js b/server/src/shape.js index 721ab11..f3f89cd 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -64,7 +64,7 @@ export function loadLinks(db, ownerKind, ids) { rather than no key, so the renderer never has to check. ───────────────────────────────────────────────────────────── */ -export function loadBlocks(db, ownerKind, ids, slot = "body") { +export function loadBlocks(db, ownerKind, ids, slot = "body", depth = 0) { const out = new Map(); if (ids.length === 0) return out; @@ -175,7 +175,7 @@ export function loadBlocks(db, ownerKind, ids, slot = "body") { } attachVenues(db, [...byId.values()]); - attachEvents(db, [...byId.values()]); + attachEvents(db, [...byId.values()], depth); return out; } @@ -220,8 +220,13 @@ function attachVenues(db, blocks) { schedule entry or sub-item that is a workshop, which takes what it leaves blank from its event: the link, the description (its card text), the graphic (its photo) and the person (a person - host). An unpublished event is no event. */ -function attachEvents(db, blocks) { + host). An unpublished event is no event. + + An events block's event also brings its own page's blocks + (`blocks`), drawn when its card is opened. Only at the top + (`depth` 0): a workshop's blocks don't bring theirs, so two + events listing each other can't go round forever. */ +function attachEvents(db, blocks, depth = 0) { const entries = []; const walk = (entry) => { entries.push(entry); @@ -234,7 +239,8 @@ function attachEvents(db, blocks) { const rows = db .prepare( `SELECT e.id, e.title, e.tagline, e.event_type, e.starts_on, e.ends_on, e.date_label, - e.effective_color AS color, COALESCE(e.card_image, e.photo) AS image, e.photo_alt, + e.effective_color AS color, COALESCE(e.card_image, e.photo) AS image, e.photo, e.photo_alt, + e.location_label, p.id AS person_id, p.display_name AS person_name, p.photo AS person_photo, p.tagline AS person_tagline FROM v_events e @@ -244,6 +250,9 @@ function attachEvents(db, blocks) { .all(...ids); const cards = loadBlocks(db, "event", rows.map((row) => row.id), "card"); const events = new Map(rows.map((row) => [row.id, row])); + const shown = blocks.filter((block) => block.type === "events").flatMap((block) => block.items); + const shownIds = [...new Set(shown.map((item) => item.event_id).filter((id) => events.has(id)))]; + const bodies = depth === 0 && shownIds.length ? loadBlocks(db, "event", shownIds, "body", depth + 1) : new Map(); for (const entry of entries) { const row = events.get(entry.event_id); @@ -261,8 +270,12 @@ function attachEvents(db, blocks) { date_label: row.date_label, color: row.color, image: row.image, + photo: row.photo, + photo_alt: row.photo_alt, + location_label: row.location_label, blurb, }; + if (shown.includes(entry)) entry.event.blocks = bodies.get(row.id) ?? []; entry.url ||= `/events/${row.id}`; entry.description ||= blurb; if (!entry.media && row.image) { diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx index 0b315da..9fb8e65 100644 --- a/src/components/ContentBlocks.tsx +++ b/src/components/ContentBlocks.tsx @@ -35,7 +35,9 @@ link to it events items as event cards: event (from event_id), text the title shown, detail - in place of the event's card text + in place of the event's card text; a card + opens the event in full under them, its + own page's blocks too (EventsBlock) divider nothing "Formatted" is InlineText.tsx: **bold**, *italic*, [text](url), @@ -50,14 +52,18 @@ visible even if the renderer hasn't caught up with it. ═══════════════════════════════════════════════════════════════ */ +import { CaretDown } from '@phosphor-icons/react' +import { useEffect, useId, useRef, useState } from 'react' +import { Link } from 'react-router-dom' + import { mediaUrl } from '../lib/media.ts' import PeopleTiles from './PeopleTiles.tsx' import type { ContentBlock, ContentBlockItem, ItemEvent } from '../lib/useContent.ts' import { Anchor, Inline, Paragraphs, isExternalUrl } from './InlineText.tsx' import VideoPlayer from './VideoPlayer.tsx' -import ScheduleBlock from './ScheduleBlock.tsx' +import ScheduleBlock, { Avatar } from './ScheduleBlock.tsx' import MapBlock, { PageMaps } from './MapBlock.tsx' -import { eventHref } from '../lib/hrefs.ts' +import { eventHref, personHref } from '../lib/hrefs.ts' import { occurrenceLabel } from '../lib/eventSeries.ts' import { accentText, BRAND } from '../lib/color.ts' import { headingAnchors } from '../lib/contents.ts' @@ -160,15 +166,34 @@ export function eventLine(event: ItemEvent): string | null { return [kind, when].filter(Boolean).join(' · ') || null } -function EventCard({ item, accent }: { item: ContentBlockItem; accent: string }) { +function EventCard({ + item, + accent, + open, + panelId, + onToggle, +}: { + item: ContentBlockItem + accent: string + open: boolean + panelId: string + onToggle: () => void +}) { const event = item.event! const img = useSmallImage(mediaUrl(event.image)) const color = event.color || accent const line = eventLine(event) return ( - {!img.failed && ( @@ -185,8 +210,101 @@ function EventCard({ item, accent }: { item: ContentBlockItem; accent: string }) {(item.detail || event.blurb) && ( {item.detail || event.blurb} )} + + {open ? 'Close' : 'More'} + - + + ) +} + +/* An event in full (088): its photo, type and date, title, place and + person host, then its own page's blocks (else its card text), and + a link to its page. */ +function EventInFull({ item, accent, level }: { item: ContentBlockItem; accent: string; level: 3 | 4 | 5 }) { + const event = item.event! + const color = event.color || accent + const photo = mediaUrl(event.photo || event.image) + const line = eventLine(event) + const Title = `h${level}` as 'h3' + const blurb = item.detail || event.blurb + return ( +
+ {photo && {event.photo_alt} +
+ {line && ( +

+ {line} +

+ )} + {item.text || event.title} + {(event.location_label || item.person) && ( +

+ {event.location_label && {event.location_label}} + {item.person && ( + + + {item.person.name} + + )} +

+ )} +
+ {event.blocks?.length ? ( + + ) : blurb ? ( +
+ +
+ ) : null} + + {event.title}: the event's page + +
+ ) +} + +/* An events block (088): its events as cards; one opened shows in + full under them, scrolled into view. Reading mode has them all in + full. */ +function EventsBlock({ items, accent, level }: { items: ContentBlockItem[]; accent: string; level: 3 | 4 | 5 }) { + const [open, setOpen] = useState(null) + const panelId = useId() + const panel = useRef(null) + const reading = useReadingMode() + useEffect(() => { + if (open != null) panel.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' }) + }, [open]) + + if (reading) { + return ( +
+ {items.map((item, i) => ( + + ))} +
+ ) + } + return ( +
+
    + {items.map((item, i) => ( +
  • + setOpen(open === i ? null : i)} + /> +
  • + ))} +
+
+ {open != null && items[open] && } +
+
) } @@ -445,15 +563,7 @@ function Block({ case 'events': { const events = (block.items ?? []).filter((item) => item.event) if (events.length === 0) return null - return ( - - ) + return } case 'people': { diff --git a/src/lib/useContent.ts b/src/lib/useContent.ts index fd5c42d..a9f8819 100644 --- a/src/lib/useContent.ts +++ b/src/lib/useContent.ts @@ -95,7 +95,13 @@ export type ItemEvent = { date_label?: string | null color?: string | null image?: string | null + /** Its own 16:9 photo, and where it is, for showing it in full. */ + photo?: string | null + photo_alt?: string | null + location_label?: string | null blurb?: string | null + /** Its own page's blocks: an events block's events only. */ + blocks?: ContentBlock[] } /** A schedule's tag (087). `tab` is whether it gets a tab of its own. */ diff --git a/src/pages/EventPresent.tsx b/src/pages/EventPresent.tsx index b8a5d42..187fee2 100644 --- a/src/pages/EventPresent.tsx +++ b/src/pages/EventPresent.tsx @@ -14,8 +14,8 @@ venue each map block (088): the map with its locations place then the map once per marked location, it lit up cards each events block (088): its events on one slide - event then each event alone: picture, title, card text - and its person host + event then each event alone: picture, title, its person + host and its own page's blocks (else its card text) A schedule's slides, for each day picked, in order: overview the day's picked entries on one slide @@ -1040,6 +1040,10 @@ function SlideView({ slide, accent }: { slide: Slide; accent: string }) { const event = entry.event! const image = mediaUrl(event.image) const blurb = entry.detail || event.blurb + // Its own page's blocks, when it has some, in place of its card + // text, zoomed for the column they're in. + const blocks = event.blocks?.length ? event.blocks : null + const zoom = Math.max(1, (window.innerWidth * 0.75) / TEXT_WIDTH) return (
{image && ( @@ -1047,7 +1051,7 @@ function SlideView({ slide, accent }: { slide: Slide; accent: string }) { )} - + {eventLine(event) && (

@@ -1060,15 +1064,8 @@ function SlideView({ slide, accent }: { slide: Slide; accent: string }) { {entry.text || event.title} - {blurb && ( - -

- -
-
- )} {entry.person && ( - + {entry.person.name} @@ -1078,6 +1075,21 @@ function SlideView({ slide, accent }: { slide: Slide; accent: string }) { )} + {blocks ? ( + +
+ +
+
+ ) : ( + blurb && ( + +
+ +
+
+ ) + )}
)