diff --git a/server/src/admin-schema/columns.js b/server/src/admin-schema/columns.js index 16f989f..cfbbdd7 100644 --- a/server/src/admin-schema/columns.js +++ b/server/src/admin-schema/columns.js @@ -264,6 +264,15 @@ export const blocksChild = (ownerKind) => ({ bool("no_tab"), ], }, + { + // A map block's own sections of its venue's locations (094). + key: "map_sections", + table: "content_block_map_sections", + owner: { column: "block_id" }, + order: "sort_order", + when: { column: "type", value: "map" }, + columns: [text("name", { required: true }), text("location_keys")], + }, ], }); diff --git a/server/src/migrations/094_map_sections.sql b/server/src/migrations/094_map_sections.sql new file mode 100644 index 0000000..567a2cb --- /dev/null +++ b/server/src/migrations/094_map_sections.sql @@ -0,0 +1,27 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 094 A MAP BLOCK'S SECTIONS +-- +-- A map content block can group its venue's locations into +-- sections of its own, eg. Main spaces, Small group spaces: the +-- block's list shows them under those names, and a visitor can pick +-- one to see only its locations on the map. They're the block's, +-- not the venue's, so each event groups the same venue its own way. +-- +-- With sections, the block shows only the locations they name (in +-- the sections' order); without, every location, as before. +-- +-- location_keys the venue's location_keys (088) it holds, +-- comma-separated, as schedule tags are (087). A +-- key the venue no longer has is skipped. +-- ═══════════════════════════════════════════════════════════════ + +CREATE TABLE content_block_map_sections ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + block_id INTEGER NOT NULL REFERENCES content_blocks (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + name TEXT NOT NULL, + location_keys TEXT +) STRICT; + +CREATE INDEX content_block_map_sections_block_idx + ON content_block_map_sections (block_id, sort_order); diff --git a/server/src/shape.js b/server/src/shape.js index 64f7c76..d3c7aa2 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -187,6 +187,32 @@ export function loadBlocks(db, ownerKind, ids, slot = "body", depth = 0) { attachVenues(db, [...byId.values()]); attachEvents(db, [...byId.values()], depth); + // A map block's sections (094): each names some of its venue's + // locations. With any, the block's venue is cut to the locations + // they name, in their order, so the page, its schedule's links + // and the presentation all see the same places, numbered alike. + const sectionRows = db + .prepare( + `SELECT block_id, name, location_keys + FROM content_block_map_sections + WHERE block_id IN (${placeholders(blockIds.length)}) + ORDER BY block_id, sort_order`, + ) + .all(...blockIds); + for (const row of sectionRows) { + const block = byId.get(row.block_id); + if (!block?.venue) continue; + const known = new Set(block.venue.locations.map((location) => location.key)); + const keys = (row.location_keys ?? "").split(",").filter((key) => known.has(key)); + if (keys.length) (block.map_sections ??= []).push({ name: row.name, keys }); + } + for (const block of byId.values()) { + if (!block.map_sections) continue; + const byKey = new Map(block.venue.locations.map((location) => [location.key, location])); + const shown = [...new Set(block.map_sections.flatMap((section) => section.keys))]; + block.venue = { ...block.venue, locations: shown.map((key) => byKey.get(key)) }; + } + return out; } diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx index 57a11a7..27fa2a7 100644 --- a/src/components/ContentBlocks.tsx +++ b/src/components/ContentBlocks.tsx @@ -62,7 +62,7 @@ import type { ContentBlock, ContentBlockItem, ItemEvent } from '../lib/useConten import { Anchor, Inline, Paragraphs, isExternalUrl } from './InlineText.tsx' import VideoPlayer from './VideoPlayer.tsx' import ScheduleBlock, { Avatar } from './ScheduleBlock.tsx' -import MapBlock, { PageMaps } from './MapBlock.tsx' +import MapBlock, { PageMaps, mapAnchor } from './MapBlock.tsx' import { eventHref, personHref } from '../lib/hrefs.ts' import { occurrenceLabel } from '../lib/eventSeries.ts' import { accentText, BRAND } from '../lib/color.ts' @@ -102,8 +102,15 @@ export default function ContentBlocks({ }) - // The venues mapped here, for a schedule's places to link to. - const maps = new Set(blocks.flatMap((block) => (block.type === 'map' && block.venue ? [block.venue.id] : []))) + // The places mapped here, for a schedule's places to link to: a + // map block's venue's locations (only those its sections show). + const maps = new Set( + blocks.flatMap((block) => + block.type === 'map' && block.venue + ? block.venue.locations.map((location) => mapAnchor(block.venue!.id, location.key)) + : [], + ), + ) return ( @@ -588,7 +595,7 @@ function Block({ case 'map': if (!block.venue) return null - return + return case 'events': { const events = (block.items ?? []).filter((item) => item.event) diff --git a/src/components/MapBlock.tsx b/src/components/MapBlock.tsx index 036c168..3778e80 100644 --- a/src/components/MapBlock.tsx +++ b/src/components/MapBlock.tsx @@ -23,17 +23,24 @@ Reading mode (readingMode.ts) gets the list alone, no picture. - PageMaps holds the venues that have a map block among the blocks - drawn together (ContentBlocks), so a schedule's places link only - when there's a map on the page to go to. + A block's own sections (094), eg. Main spaces, group the list + under their names; the API has already cut the venue to the + locations they hold. Buttons over the list (All, then one per + section) show one section alone, its marks on the map and its + rows in the list. A link to a location outside the section in + view goes back to All. + + PageMaps holds the locations mapped by the blocks drawn together + (their anchors, ContentBlocks), so a schedule's places link only + when there's a map on the page showing them. ═══════════════════════════════════════════════════════════════ */ -import { createContext, useState, type CSSProperties, type ReactNode } from 'react' +import { createContext, useEffect, useState, type CSSProperties, type ReactNode } from 'react' import { AppleLogo, ArrowsIn, GoogleLogo, MagnifyingGlassMinus, MagnifyingGlassPlus } from '@phosphor-icons/react' import { Link, useLocation, type To } from 'react-router-dom' import { mediaUrl } from '../lib/media.ts' -import type { Venue, VenueLocation } from '../lib/useContent.ts' +import type { MapSection, Venue, VenueLocation } from '../lib/useContent.ts' import { accentText, readableOn, withAlpha } from '../lib/color.ts' import { useReadingMode } from '../lib/readingMode.ts' @@ -85,10 +92,13 @@ export function MapPicture({ light, className = '', big = false, + only, }: { venue: Venue accent: string active: string | null + /** Marks only these locations' keys; all when unset. */ + only?: Set link?: (key: string) => To light?: (key: string) => object className?: string @@ -100,7 +110,7 @@ export function MapPicture({ return (
{venue.map_alt - {venue.locations.filter(isMarked).map((location) => { + {venue.locations.filter((location) => isMarked(location) && (!only || only.has(location.key))).map((location) => { const on = active === location.key const dim = active != null && !on const style: CSSProperties = isBox(location) @@ -170,11 +180,36 @@ export function MapPicture({ ) } -export default function MapBlock({ venue, accent }: { venue: Venue; accent: string }) { +export default function MapBlock({ + venue, + sections = [], + accent, +}: { + venue: Venue + sections?: MapSection[] + accent: string +}) { const { hash, search } = useLocation() const [hovered, setHovered] = useState(null) const [zoom, setZoom] = useState(0) + // The section in view, by index; null is All. + const [view, setView] = useState(null) const fromHash = venue.locations.find((location) => hash === `#${mapAnchor(venue.id, location.key)}`)?.key ?? null + const viewed = view != null ? sections[view] : undefined + + // A link to a place outside the section in view shows All again. + useEffect(() => { + if (fromHash && viewed && !viewed.keys.includes(fromHash)) setView(null) + }, [fromHash, viewed]) + + const byKey = new Map(venue.locations.map((location) => [location.key, location])) + const groups: { name?: string; locations: VenueLocation[] }[] = sections.length + ? (viewed ? [viewed] : sections).map((section) => ({ + name: section.name, + locations: section.keys.flatMap((key) => byKey.get(key) ?? []), + })) + : [{ locations: venue.locations }] + const only = viewed ? new Set(viewed.keys) : undefined const active = hovered ?? fromHash const picture = !useReadingMode() && Boolean(venue.map_image) @@ -197,7 +232,7 @@ export default function MapBlock({ venue, accent }: { venue: Venue; accent: stri
- +
@@ -219,36 +254,64 @@ export default function MapBlock({ venue, accent }: { venue: Venue; accent: stri

{venue.name}

{venue.address &&

{venue.address}

} -
    - {venue.locations.map((location) => { - const on = active === location.key - const row = ( - <> - - - - {location.name} - - {location.detail && {location.detail}} - - - ) - const rowClass = 'flex items-start gap-3 px-2 py-1.5 text-body' - const rowStyle = on ? { background: withAlpha(accent, 12) } : undefined - return ( -
  1. - {isMarked(location) ? ( - - {row} - - ) : ( -
    {row}
    - )} - -
  2. - ) - })} -
+ {sections.length > 1 && ( +
+ {[null, ...sections.map((_, i) => i)].map((i) => { + const selected = view === i + return ( + + ) + })} +
+ )} + {groups.map((group, g) => ( +
+ {group.name &&

{group.name}

} +
    + {group.locations.map((location) => { + const on = active === location.key + const row = ( + <> + + + + {location.name} + + {location.detail && {location.detail}} + + + ) + const rowClass = 'flex items-start gap-3 px-2 py-1.5 text-body' + const rowStyle = on ? { background: withAlpha(accent, 12) } : undefined + return ( +
  1. + {isMarked(location) ? ( + + {row} + + ) : ( +
    {row}
    + )} + +
  2. + ) + })} +
+
+ ))}
) diff --git a/src/components/ScheduleBlock.tsx b/src/components/ScheduleBlock.tsx index b5c838a..daa5406 100644 --- a/src/components/ScheduleBlock.tsx +++ b/src/components/ScheduleBlock.tsx @@ -149,7 +149,7 @@ function Place({ entry, accent }: { entry: ContentBlockItem; accent: string }) { const maps = useContext(PageMaps) const { search } = useLocation() if (!entry.location) return null - if (!entry.place || !maps.has(entry.place.venue_id)) return {entry.location} + if (!entry.place || !maps.has(mapAnchor(entry.place.venue_id, entry.place.key))) return {entry.location} return ( row.name || "New section", + blank: { name: "" }, + fields: [ + { path: "name", label: "Name", required: true, help: "eg. Main spaces" }, + { + path: "location_keys", + label: "Locations", + widget: "checklist", + optionsFrom: "mapLocations", + full: true, + emptyNote: "No locations yet: pick the block's Venue, and give it locations under Data → Venues.", + }, + ], + }, { key: "items", label: "Items", diff --git a/src/lib/useContent.ts b/src/lib/useContent.ts index ebb747e..f949890 100644 --- a/src/lib/useContent.ts +++ b/src/lib/useContent.ts @@ -67,8 +67,13 @@ export type ContentBlock = { /** A map or schedule block's venue (088). */ venue_id?: string | null venue?: Venue | null + /** A map block's own sections of its venue's locations, by key + * (094). With any, `venue` holds only the locations they name. */ + map_sections?: MapSection[] } +export type MapSection = { name: string; keys: string[] } + /** A venue (088): its map picture and the locations marked on it, * each a pin (x, y) or a box (x, y, w, h), in percent. */ export type Venue = {