import { CaretRight, X } from '@phosphor-icons/react'; import { useEffect, useRef, useState } from "react"; import { useCommunity } from "../../lib/useCommunity.ts"; import { Link } from "react-router-dom"; import ArrowLink from "../../components/ArrowLink.tsx"; import OrgLogo from "../../components/OrgLogo.tsx"; import { orgPath } from "../../lib/organizations.ts"; import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts"; import { withAlpha, accentText, readableOn } from '../../lib/color.ts' import { scrollBehavior } from "../../lib/motion.ts"; /* ═══════════════════════════════════════════════════════════════ ORGANIZATION LIST: MAP Organizations placed on a tile grid: the map on the left, the list on the right, selecting on either side filtering both. Filtered to groups, and unlike the other sections that isn't a prop. A map only makes sense for organizations that sit somewhere, and it reads regions off the same data to color the tiles, so "plot partners instead" isn't a filter change, it's a different component. Named for the view rather than the filter so that stays visible. Why a tile grid rather than a geographic map: every state reads at the same size (so Rhode Island is as clickable as Texas), it stays legible on a phone, it needs no map library or GeoJSON, and a state split between two regions is just a tile painted in two colors. If you later want true geography, the swap point is , everything else works off the data. The tile layout comes from mapGrid.ts; who paints what comes from the API. A state and the Canada band are the same shape now, a tile with a span, so the map is one loop. ═══════════════════════════════════════════════════════════════ */ const TILE = 100; const PAD = 5; const COLS = 13; const ROWS = 7; // How wide the map + list block runs. The section heading above it // stays at max-w-6xl, so this deliberately breaks out past it. const CONTENT_MAX = "88rem"; const MUTED = "var(--color-muted)"; const RULE = "color-mix(in srgb, var(--color-muted) 25%, transparent)"; const INK = "var(--color-body)"; const FALLBACK_COLOR = "#4a6b72"; /* organizations.color is nullable; an SVG fill left undefined paints black, so an uncolored region takes the same fallback as a card. */ const colorOf = (item) => item.color || FALLBACK_COLOR; const US_TITLE = "US Unity Regions"; const INTL_TITLE = "International Unity Regions"; /* ── Body content ────────────────────────────────────────────── A group's description is ordered blocks rather than one string, so a heading or a list added later renders instead of vanishing. When organization and person pages arrive this should move to a shared component; small enough to live here until then. ───────────────────────────────────────────────────────────── */ function Blocks({ blocks = [] as any[], color }) { if (blocks.length === 0) return null; return (
{blocks.map((block, i) => { switch (block.type) { case "heading": return (

{block.text}

); case "subheading": return (
{block.text}
); case "quote": return (
{block.text}
); case "list": case "links": return ( ); case "divider": return
; default: return (

{block.text}

); } })}
); } /* ── Tile ────────────────────────────────────────────────────── Every region painting this tile gets its own rect. A whole tile is one slice with no edge; a shared tile is two, each declaring which edge it sits on and how much it takes. Nothing here subtracts, and the order the slices arrive in doesn't change what's drawn. ───────────────────────────────────────────────────────────── */ function Tile({ code, x, y, size, width = size, label, slices = [] as any[], count = 0, selected, hovered, setSelected, setHovered, onPick, fontSize = 34, }) { if (slices.length === 0) return null; const primary = slices[0]; const ids = slices.map(s => s.regionId); const active = ids.includes(selected) || ids.includes(hovered); const dimmed = selected && !ids.includes(selected); const clipId = `clip-${code}`; const opacity = count ? 1 : active ? 0.5 : 0.28; // Clicking a shared tile cycles through its regions and then // clears, so every slice is reachable without a second control. const cycle = () => { onPick?.(code); const at = ids.indexOf(selected); setSelected(at === ids.length - 1 ? null : ids[at + 1]); }; return ( setHovered(primary.regionId)} onMouseLeave={() => setHovered(null)} style={{ cursor: "pointer" }} opacity={dimmed ? 0.25 : 1} className="transition-opacity duration-200" > {AREA_NAMES[code] || code}: {slices.map(s => s.name).join(" / ")} {count ? ` · ${count} group${count > 1 ? "s" : ""}` : ""} {slices.map(slice => { const h = slice.edge ? size * slice.share : size; const top = slice.edge === "bottom" ? y + size - h : y; return ( ); })} {label || code} {count > 0 && ( )} ); } function RegionMap({ slices, groupCounts, ...props }: any) { const size = TILE - PAD * 2; return ( {/* States and bands are the same shape, a tile with a span, so this is one loop rather than two. */} {AREAS.map(area => ( ))} ); } function LegendButton({ region, selected, setSelected, hovered, setHovered }) { const on = selected === region.id || hovered === region.id; return ( ); } function Legend({ domestic, international, onMapIds, ...props }: any) { const { selected, setSelected } = props; // A region is on the map if it paints a tile. West Central used // to need a hardcoded exception here because its states arrived // only through SPLITS; it has ordinary rows now, so the exception // is gone. const onMap = region => onMapIds.has(region.id); const us = domestic.filter(onMap); const intl = international.filter(onMap); return (

{US_TITLE}

{us.map(r => ( ))}

{INTL_TITLE}

{intl.map(r => ( ))} {selected && ( )}
); } function RegionBlock({ region, groups, subtext, selected, setSelected, setHovered, indent, regionRefs, groupRefs, }) { const on = selected === region.id; return (
regionRefs && (regionRefs.current[region.id] = el)} className="transition-opacity duration-200" style={{ opacity: selected && !on ? 0.35 : 1, marginLeft: indent ? "0.75rem" : 0 }} > {/* The heading holds the button, not the other way round: a heading inside a button stops being a heading. */}

{subtext && (

{subtext}

)} {groups.length === 0 ? (

No groups yet. Interested in starting one?

) : (
    {groups.map(c => (
  • groupRefs && (groupRefs.current[c.id] = el)} className="pl-3 flex items-start gap-3" style={{ borderLeft: `2px solid ${colorOf(region)}` }} >

    {c.name}

    {c.location_label} {c.meets ? ` · ${c.meets}` : ""}

    {(c.website || c.email) && (

    {c.website && ( Details )} {c.email && ( Contact )}

    )}
    {orgPath(c) && ( )}
  • ))}
)}
); } /* ═══════════════════════════════════════════════════════════════ GRID VIEW One grid per region. Clicking a card's arrow opens a detail panel directly above that region's grid, framed in the region color. Selecting another card swaps the panel's contents. ═══════════════════════════════════════════════════════════════ */ function GroupCard({ group, color, open, onOpen }) { return (

{group.name}

{group.location_label}

{group.meets && (

{group.meets}

)}
{/* Two controls, two destinations: the chevron opens the detail panel in place, the arrow leaves for the group's own page. Keeping them distinct beats one control that does different things depending on where you click. */}
{orgPath(group) && ( )}
); } function GroupDetail({ group, region, onClose }) { /* "Led by" comes from affiliations rather than a text field, so it lists real people and stays empty until they exist. */ const leads = (group.leadership ?? []) .map(person => person.title ? `${person.display_name} (${person.title})` : person.display_name ) .join(", "); const rows = [ ["Region", region.name], ["Where", group.venue], ["Meets", group.meets], ["Led by", leads], ["Since", group.started], ].filter(([, v]) => v); return (

{group.name}

{group.location_label}

{rows.length > 0 && (
{rows.map(([label, value]) => (
{label}
{value}
))}
)}
{orgPath(group) && ( Group page )} {group.website && ( Visit site )} {group.email && ( Get in touch )}
); } function GroupGrid({ regions, groups, groupsIn, subtextFor, openId, setOpenId }) { // Only regions that actually have groups get a grid. const populated = regions .map(region => ({ region, list: groupsIn(region.id) })) .filter(({ list }) => list.length > 0); const empty = regions.filter(region => groupsIn(region.id).length === 0); const openGroup = groups.find(c => c.id === openId) || null; return (
{populated.map(({ region, list }) => { const subtext = subtextFor(region); return (

{region.name}

{list.length}
{subtext && (

{subtext}

)} {/* Detail panel sits above this region's grid, and only when the open group belongs to this region. */} {openGroup && openGroup.region_id === region.id && ( setOpenId(null)} /> )}
{list.map(c => ( setOpenId(openId === c.id ? null : c.id)} /> ))}
); })} {empty.length > 0 && (

No groups yet in {empty.map(r => r.name).join(", ")}. Interested in starting one?

)}
); } /* The control for the section heading's action bar. */ export function OrgMapToggle({ view, setView, accent }) { const btn = active => ({ background: active ? accent : "transparent", color: active ? readableOn(accent) : accentText(accent), }); return (
{[ ["map", "Map"], ["grid", "Grid"], ].map(([id, label]) => ( ))}
); } export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) { const { loading, error, regions, regionAreas, domestic, international, virtual, groups, groupsIn, slices, groupCounts, regionsForArea, subtextFor, } = useCommunity(); const [selected, setSelected] = useState(null); const [hovered, setHovered] = useState(null); const [openId, setOpenId] = useState(null); // no card open on arrival // The list scrolls itself to whatever the map or legend points at. const listRef = useRef(null); const regionRefs = useRef({}); const groupRefs = useRef({}); // Where the latest hover came from. The list follows the map and // the legend, but hovering the list itself must not move it: the // row would slide out from under the pointer. const hoverFromList = useRef(false); const hoverOnMap = id => { hoverFromList.current = false; setHovered(id); }; const hoverInList = id => { hoverFromList.current = true; setHovered(id); }; const scrollListTo = el => { const box = listRef.current; if (!box || !el) return; // Only when the list is its own scroll area (lg and up). Below // that it's stacked under the map and scrolling it would fight // the page. if (box.scrollHeight <= box.clientHeight) return; box.scrollTo({ top: el.offsetTop - 8, behavior: scrollBehavior() }); }; // Hovering or selecting a region on the map or legend brings its // block into view. After a hover in the list, nothing scrolls: not // on the way in, and not back to the selection on the way out. useEffect(() => { if (hoverFromList.current) return; const id = hovered || selected; if (id) scrollListTo(regionRefs.current[id]); }, [hovered, selected]); // Clicking a tile jumps to its first group when it has one, // otherwise to the region it belongs to. const pickArea = code => { const group = groups.find(c => c.area_code === code); if (group && groupRefs.current[group.id]) { return scrollListTo(groupRefs.current[group.id]); } const region = regionsForArea(code)[0]; if (region) scrollListTo(regionRefs.current[region.id]); }; const shell = children => (
{children}
); if (loading && regions.length === 0) { return shell(
); } if (error && regions.length === 0) { return shell(

· Groups couldn't be loaded just now, please try again shortly ·

); } if (view === "grid") { return ( ); } const shared = { selected, setSelected, hovered, setHovered: hoverOnMap }; const onMapIds = new Set(regionAreas.map(a => a.region_id)); const block = (region, indent) => ( ); return ( /* Wider than the section heading above it, the map needs the room. CONTENT_MAX is the knob; drop it toward 72rem to pull the whole block back in line with the heading. */ shell(
{/* Map */}

A filled tile means a group meets there; a two-tone tile is a state shared by two Unity regions. Select a region to filter the list.

{/* List, h-0 + min-h-full makes this column take its height from the map column rather than the other way round, so a long list scrolls instead of stretching the section. */}

{US_TITLE}

{domestic.map(r => block(r, true))}

{INTL_TITLE}

{international.map(r => block(r, true))}
{virtual.map(r => block(r, false))}
) ); }