Events block: a card opens the event in full, its own blocks too
An events block's events bring their own page's blocks (one level deep, so events listing each other stop there), photo and place. A card opens the event under the cards: photo, type and date, title, place, person host, its blocks (else its card text) and a link to its page. Reading mode shows them all in full, and the presentation's event spotlight shows its blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
df8052c75e
commit
375c364861
4 changed files with 174 additions and 33 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue