Map block: sections of its own, shown one at a time
Migration 094 adds content_block_map_sections: a map block groups its venue's locations for its page, eg. Main spaces, without changing the venue. With sections the API cuts the block's venue to the locations they hold, in their order; the list groups under their names, and buttons (All, then each section) show one section's marks and rows. A schedule's place links only when a map on the page shows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
06bf033448
commit
56a6e11655
8 changed files with 200 additions and 43 deletions
|
|
@ -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 (
|
||||
<PageMaps.Provider value={maps}>
|
||||
|
|
@ -588,7 +595,7 @@ function Block({
|
|||
|
||||
case 'map':
|
||||
if (!block.venue) return null
|
||||
return <MapBlock venue={block.venue} accent={accent} />
|
||||
return <MapBlock venue={block.venue} sections={block.map_sections} accent={accent} />
|
||||
|
||||
case 'events': {
|
||||
const events = (block.items ?? []).filter((item) => item.event)
|
||||
|
|
|
|||
|
|
@ -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<string>
|
||||
link?: (key: string) => To
|
||||
light?: (key: string) => object
|
||||
className?: string
|
||||
|
|
@ -100,7 +110,7 @@ export function MapPicture({
|
|||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<img src={image} alt={venue.map_alt || `Map of ${venue.name}`} className="block w-full" />
|
||||
{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<string | null>(null)
|
||||
const [zoom, setZoom] = useState(0)
|
||||
// The section in view, by index; null is All.
|
||||
const [view, setView] = useState<number | null>(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
|
|||
<div className="relative self-start">
|
||||
<div className="max-h-[80vh] overflow-auto border border-brand/15">
|
||||
<div style={{ width: `${ZOOMS[zoom] * 100}%` }}>
|
||||
<MapPicture venue={venue} accent={accent} active={active} link={to} light={light} />
|
||||
<MapPicture venue={venue} accent={accent} active={active} link={to} light={light} only={only} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="absolute top-2 right-2 flex gap-1">
|
||||
|
|
@ -219,36 +254,64 @@ export default function MapBlock({ venue, accent }: { venue: Venue; accent: stri
|
|||
<figcaption className={picture ? '' : 'md:col-span-2'}>
|
||||
<p className="font-display font-bold text-ink">{venue.name}</p>
|
||||
{venue.address && <p className="text-sm text-muted">{venue.address}</p>}
|
||||
<ol className="mt-3 space-y-1">
|
||||
{venue.locations.map((location) => {
|
||||
const on = active === location.key
|
||||
const row = (
|
||||
<>
|
||||
<LocationNumber n={locationNumber(venue, location)} accent={accent} />
|
||||
<span className="min-w-0">
|
||||
<span className="block font-semibold" style={on ? { color: accentText(accent) } : undefined}>
|
||||
{location.name}
|
||||
</span>
|
||||
{location.detail && <span className="block text-sm text-muted">{location.detail}</span>}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
const rowClass = 'flex items-start gap-3 px-2 py-1.5 text-body'
|
||||
const rowStyle = on ? { background: withAlpha(accent, 12) } : undefined
|
||||
return (
|
||||
<li key={location.key} className="flex items-start gap-2">
|
||||
{isMarked(location) ? (
|
||||
<Link to={to(location.key)} {...light(location.key)} className={`${rowClass} flex-1`} style={rowStyle}>
|
||||
{row}
|
||||
</Link>
|
||||
) : (
|
||||
<div className={`${rowClass} flex-1`}>{row}</div>
|
||||
)}
|
||||
<MapLinks location={location} accent={accent} />
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ol>
|
||||
{sections.length > 1 && (
|
||||
<div role="group" aria-label="Show" className="mt-3 flex flex-wrap gap-2">
|
||||
{[null, ...sections.map((_, i) => i)].map((i) => {
|
||||
const selected = view === i
|
||||
return (
|
||||
<button
|
||||
key={i ?? 'all'}
|
||||
type="button"
|
||||
aria-pressed={selected}
|
||||
onClick={() => setView(i)}
|
||||
className="btn border px-3 py-1 text-xs transition-colors"
|
||||
style={
|
||||
selected
|
||||
? { background: accent, borderColor: accent, color: readableOn(accent) }
|
||||
: { borderColor: withAlpha(accent, 33), color: accentText(accent) }
|
||||
}
|
||||
>
|
||||
{i == null ? 'All' : sections[i].name}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{groups.map((group, g) => (
|
||||
<div key={group.name ?? g} className="mt-3">
|
||||
{group.name && <p className="px-2 text-sm font-bold text-ink">{group.name}</p>}
|
||||
<ol className="mt-1 space-y-1">
|
||||
{group.locations.map((location) => {
|
||||
const on = active === location.key
|
||||
const row = (
|
||||
<>
|
||||
<LocationNumber n={locationNumber(venue, location)} accent={accent} />
|
||||
<span className="min-w-0">
|
||||
<span className="block font-semibold" style={on ? { color: accentText(accent) } : undefined}>
|
||||
{location.name}
|
||||
</span>
|
||||
{location.detail && <span className="block text-sm text-muted">{location.detail}</span>}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
const rowClass = 'flex items-start gap-3 px-2 py-1.5 text-body'
|
||||
const rowStyle = on ? { background: withAlpha(accent, 12) } : undefined
|
||||
return (
|
||||
<li key={location.key} className="flex items-start gap-2">
|
||||
{isMarked(location) ? (
|
||||
<Link to={to(location.key)} {...light(location.key)} className={`${rowClass} flex-1`} style={rowStyle}>
|
||||
{row}
|
||||
</Link>
|
||||
) : (
|
||||
<div className={`${rowClass} flex-1`}>{row}</div>
|
||||
)}
|
||||
<MapLinks location={location} accent={accent} />
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ol>
|
||||
</div>
|
||||
))}
|
||||
</figcaption>
|
||||
</figure>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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 <span>{entry.location}</span>
|
||||
if (!entry.place || !maps.has(mapAnchor(entry.place.venue_id, entry.place.key))) return <span>{entry.location}</span>
|
||||
return (
|
||||
<Link
|
||||
to={{ search, hash: mapAnchor(entry.place.venue_id, entry.place.key) }}
|
||||
|
|
|
|||
|
|
@ -650,6 +650,26 @@ export const blocksChild = {
|
|||
{ path: "no_tab", label: "No tab", widget: "checkbox", help: "Leave it out of the tabs (it still shows on entries)" },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "map_sections",
|
||||
label: "Sections",
|
||||
addLabel: "Add section",
|
||||
note: "Optional: group the venue's locations for this page, eg. Main spaces, Small group spaces. Visitors can pick one to see only its places on the map. With sections, only the locations they hold are shown. The venue itself is unchanged.",
|
||||
when: { path: "type", value: "map" },
|
||||
title: (row) => 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",
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue