/* ═══════════════════════════════════════════════════════════════ MAP BLOCK The 'map' content block (088): a venue's map picture with its locations marked on it, each a numbered pin or a box, and the locations listed beside it (under it on a phone). One picture, the marks drawn over it in percent of its size, so they stay on their places at any width. A location is lit up (in the accent, the rest dimmed) while its row or mark is hovered or focused, and when the address points at it: #map--, the link a schedule entry's place makes (mapAnchor). Those ids sit at the block's top, so Layout's jump to the anchor brings the whole map into view, not the mark at the top of the screen. The picture zooms (the buttons over it), scrolling inside its box when it's bigger than it; the marks are in percent, so they keep their places. A location's Google and Apple Maps links (091) are buttons at the right of its row. MapPicture is the picture and its marks alone; the event's presentation (EventPresent.tsx) draws it too, with no links. Reading mode (readingMode.ts) gets the list alone, no picture. 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, 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 { MapSection, Venue, VenueLocation } from '../lib/useContent.ts' import { accentText, readableOn, withAlpha } from '../lib/color.ts' import { useReadingMode } from '../lib/readingMode.ts' export const PageMaps = createContext>(new Set()) export const mapAnchor = (venueId: string, key: string) => `map-${venueId}-${key}` /* The picture's zoom steps, 1 the column's width. */ const ZOOMS = [1, 1.5, 2, 3, 4] const isBox = (location: VenueLocation) => location.w != null && location.h != null export const isMarked = (location: VenueLocation) => location.x != null && location.y != null /* A location's number on the map and in the list: its place in the venue's order. */ export const locationNumber = (venue: Venue, location: VenueLocation) => venue.locations.indexOf(location) + 1 /* A location's numbered dot, in the accent. */ export function LocationNumber({ n, accent, className = 'h-6 w-6 text-xs', style, }: { n: number accent: string className?: string style?: CSSProperties }) { return ( ) } /* The venue's picture with its marks, `active` lit up. With `link` each mark is a link (and `light` its hover and focus); without, the marks are only drawn. `className` sizes the picture's box. */ export function MapPicture({ venue, accent, active, link, 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 /** Bigger marks, for a screen across a room. */ big?: boolean }) { const image = mediaUrl(venue.map_image) if (!image) return null return (
{venue.map_alt {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) ? { left: `${location.x}%`, top: `${location.y}%`, width: `${location.w}%`, height: `${location.h}%`, border: `${big ? 4 : 2}px solid ${accent}`, background: withAlpha(accent, on ? 35 : 12), opacity: dim ? 0.35 : 1, } : { left: `${location.x}%`, top: `${location.y}%`, transform: 'translate(-50%, -50%)', opacity: dim ? 0.35 : 1, zIndex: on ? 1 : undefined, } const dot = big ? isBox(location) ? 'absolute top-[0.5vw] left-[0.5vw] h-[2.6vw] w-[2.6vw] text-[1.3vw]' : on ? 'h-[4vw] w-[4vw] text-[2vw]' : 'h-[2.8vw] w-[2.8vw] text-[1.4vw]' : isBox(location) ? 'absolute top-1 left-1 h-6 w-6 text-xs' : on ? 'h-9 w-9 text-xs' : 'h-7 w-7 text-xs' const inside = ( <> {on && !big && ( )} ) return link ? ( {inside} ) : ( ) })}
) } 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) const to = (key: string) => ({ search, hash: mapAnchor(venue.id, key) }) const light = (key: string) => ({ onMouseEnter: () => setHovered(key), onMouseLeave: () => setHovered(null), onFocus: () => setHovered(key), onBlur: () => setHovered(null), }) return (
{/* Where a link to a location lands: the map's top. */} {venue.locations.map((location) => ( ))} {picture && (
setZoom(zoom + 1)}> setZoom(zoom - 1)}> {zoom > 0 && ( setZoom(0)}> )}
)}

{venue.name}

{venue.address &&

{venue.address}

} {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. ) })}
))}
) } /* A zoom button over the map picture. */ function ZoomButton({ label, disabled, onClick, children, }: { label: string disabled?: boolean onClick: () => void children: ReactNode }) { return ( ) } /* A location's Google and Apple Maps links (091), as buttons that open them in a new tab. */ function MapLinks({ location, accent }: { location: VenueLocation; accent: string }) { const links = [ { href: location.google_maps_url, label: 'Google Maps', Icon: GoogleLogo }, { href: location.apple_maps_url, label: 'Apple Maps', Icon: AppleLogo }, ].filter((link) => link.href) if (links.length === 0) return null return ( {links.map(({ href, label, Icon }) => ( ))} ) }