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
|
|
@ -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>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue