Group map: state hover, state subheadings, entry cards, scroll on click only

Hovering a tile outlines that state in ink while its region stays lit.
The list groups each region's groups under their state's subheading,
each entry a raised card, and leaves out the region's list of states
(its map note stays). The list no longer follows hover; clicking a
state jumps to its subheading (or its region when it has no groups),
and clicking a legend region to that region.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-06 04:31:19 -05:00
parent 915a7bb570
commit 96b96c3e6c

View file

@ -1,5 +1,5 @@
import { CaretRight, MagnifyingGlass, X } from '@phosphor-icons/react'; import { CaretRight, MagnifyingGlass, X } from '@phosphor-icons/react';
import { Fragment, useEffect, useMemo, useRef, useState } from "react"; import { Fragment, useMemo, useRef, useState } from "react";
import { useCommunity } from "../../lib/useCommunity.ts"; import { useCommunity } from "../../lib/useCommunity.ts";
import { useOrganization } from "../../lib/useContent.ts"; import { useOrganization } from "../../lib/useContent.ts";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
@ -157,6 +157,7 @@ function Tile({
count = 0, count = 0,
selected, selected,
hovered, hovered,
hoveredArea,
setSelected, setSelected,
setHovered, setHovered,
onPick, onPick,
@ -168,19 +169,23 @@ function Tile({
const ids = slices.map(s => s.regionId); const ids = slices.map(s => s.regionId);
const active = ids.includes(selected) || ids.includes(hovered); const active = ids.includes(selected) || ids.includes(hovered);
const dimmed = selected && !ids.includes(selected); const dimmed = selected && !ids.includes(selected);
// The state under the pointer, outlined in ink over its region's
// color, so both read at once.
const here = hoveredArea === code;
const clipId = `clip-${code}`; const clipId = `clip-${code}`;
// Solid, never see-through: a tile with no groups, or one dimmed // Solid, never see-through: a tile with no groups, or one dimmed
// while another region is picked, is its color mixed toward the // while another region is picked, is its color mixed toward the
// page's rather than faded, so the backdrop doesn't show through. // page's rather than faded, so the backdrop doesn't show through.
const strength = dimmed ? (count ? 35 : 15) : count ? 100 : active ? 50 : 28; const strength = dimmed ? (count ? 35 : 15) : count ? 100 : here ? 70 : active ? 50 : 28;
const tileFill = (color: string) => `color-mix(in srgb, ${color} ${strength}%, var(--color-surface))`; const tileFill = (color: string) => `color-mix(in srgb, ${color} ${strength}%, var(--color-surface))`;
// Clicking a shared tile cycles through its regions and then // Clicking a shared tile cycles through its regions and then
// clears, so every slice is reachable without a second control. // clears, so every slice is reachable without a second control.
const cycle = () => { const cycle = () => {
onPick?.(code);
const at = ids.indexOf(selected); const at = ids.indexOf(selected);
setSelected(at === ids.length - 1 ? null : ids[at + 1]); const next = at === ids.length - 1 ? null : ids[at + 1];
onPick?.(code, next);
setSelected(next);
}; };
const name = `${AREA_NAMES[code] || code}: ${slices.map(s => s.name).join(" / ")}${ const name = `${AREA_NAMES[code] || code}: ${slices.map(s => s.name).join(" / ")}${
@ -193,14 +198,14 @@ function Tile({
return ( return (
<g <g
onClick={cycle} onClick={cycle}
onMouseEnter={() => setHovered(primary.regionId)} onMouseEnter={() => setHovered(primary.regionId, code)}
onMouseLeave={() => setHovered(null)} onMouseLeave={() => setHovered(null)}
{...(count {...(count
? { ? {
role: "button", role: "button",
tabIndex: 0, tabIndex: 0,
"aria-label": name, "aria-label": name,
onFocus: () => setHovered(primary.regionId), onFocus: () => setHovered(primary.regionId, code),
onBlur: () => setHovered(null), onBlur: () => setHovered(null),
onKeyDown: (e) => { onKeyDown: (e) => {
if (e.key !== "Enter" && e.key !== " ") return; if (e.key !== "Enter" && e.key !== " ") return;
@ -241,9 +246,9 @@ function Tile({
width={width} width={width}
height={size} height={size}
fill="none" fill="none"
stroke={active ? colorOf(primary) : "var(--color-surface)"} stroke={here ? "var(--color-ink)" : active ? colorOf(primary) : "var(--color-surface)"}
strokeOpacity={active ? 1 : 0.55} strokeOpacity={active || here ? 1 : 0.55}
strokeWidth={active ? 4 : 2} strokeWidth={here ? 6 : active ? 4 : 2}
className="transition-all duration-200" className="transition-all duration-200"
/> />
@ -304,11 +309,14 @@ function RegionMap({ slices, groupCounts, ...props }: any) {
); );
} }
function LegendButton({ region, selected, setSelected, hovered, setHovered }) { function LegendButton({ region, selected, setSelected, hovered, setHovered, onPickRegion }) {
const on = selected === region.id || hovered === region.id; const on = selected === region.id || hovered === region.id;
return ( return (
<button <button
onClick={() => setSelected(selected === region.id ? null : region.id)} onClick={() => {
if (selected !== region.id) onPickRegion(region.id);
setSelected(selected === region.id ? null : region.id);
}}
onMouseEnter={() => setHovered(region.id)} onMouseEnter={() => setHovered(region.id)}
onMouseLeave={() => setHovered(null)} onMouseLeave={() => setHovered(null)}
onFocus={() => setHovered(region.id)} onFocus={() => setHovered(region.id)}
@ -386,9 +394,19 @@ function RegionBlock({
setHovered, setHovered,
indent, indent,
regionRefs, regionRefs,
groupRefs, stateRefs,
}) { }) {
const on = selected === region.id; const on = selected === region.id;
// Each state with groups, by name, its groups under it; groups with
// no state (online, or not placed) last, with no subheading.
const areas = new Map<string, any[]>();
for (const c of groups) {
const code = c.area_code ?? "";
areas.set(code, [...(areas.get(code) ?? []), c]);
}
const byArea = [...areas].sort(([a], [b]) =>
!a ? 1 : !b ? -1 : (AREA_NAMES[a] || a).localeCompare(AREA_NAMES[b] || b),
);
return ( return (
<div <div
@ -428,13 +446,20 @@ function RegionBlock({
No groups yet. Interested in starting one? No groups yet. Interested in starting one?
</p> </p>
) : ( ) : (
<ul className="ml-5 mb-4 flex flex-col gap-3"> <div className="ml-5 mb-4 flex flex-col gap-4">
{groups.map(c => ( {byArea.map(([code, list]) => (
<div key={code} ref={el => { if (code) stateRefs.current[`${region.id}:${code}`] = el; }}>
{code && (
<h5 className="mb-2 text-xs font-bold uppercase tracking-wide" style={{ color: MUTED }}>
{AREA_NAMES[code] || code}
</h5>
)}
<ul className="flex flex-col gap-3">
{list.map(c => (
<li <li
key={c.id} key={c.id}
ref={el => groupRefs && (groupRefs.current[c.id] = el)} className="bg-raised shadow-sm p-3 flex items-start gap-3"
className="pl-3 flex items-start gap-3" style={{ borderLeft: `3px solid ${colorOf(region)}` }}
style={{ borderLeft: `2px solid ${colorOf(region)}` }}
> >
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="font-bold">{c.name}</p> <p className="font-bold">{c.name}</p>
@ -479,6 +504,9 @@ function RegionBlock({
</li> </li>
))} ))}
</ul> </ul>
</div>
))}
</div>
)} )}
</div> </div>
); );
@ -865,26 +893,20 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
const [selected, setSelected] = useState<any>(null); const [selected, setSelected] = useState<any>(null);
const [hovered, setHovered] = useState<any>(null); const [hovered, setHovered] = useState<any>(null);
const [hoveredArea, setHoveredArea] = useState<any>(null);
const [openId, setOpenId] = useState<any>(null); // no card open on arrival const [openId, setOpenId] = useState<any>(null); // no card open on arrival
const [query, setQuery] = useState(""); const [query, setQuery] = useState("");
const reading = useReadingMode(); const reading = useReadingMode();
// The list scrolls itself to whatever the map or legend points at. // The list scrolls itself to whatever the map or legend is clicked
// on (never on hover: it would jump around as the pointer crosses).
const listRef = useRef<any>(null); const listRef = useRef<any>(null);
const regionRefs = useRef<any>({}); const regionRefs = useRef<any>({});
const groupRefs = useRef<any>({}); const stateRefs = useRef<any>({});
// Where the latest hover came from. The list follows the map and const hoverOn = (id, code = null) => {
// 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); setHovered(id);
setHoveredArea(code);
}; };
const scrollListTo = el => { const scrollListTo = el => {
@ -896,30 +918,21 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
box.scrollTo({ top: el.offsetTop - 8, behavior: scrollBehavior() }); box.scrollTo({ top: el.offsetTop - 8, behavior: scrollBehavior() });
}; };
// Hovering or selecting a region on the map or legend brings its const pickRegion = id => scrollListTo(regionRefs.current[id]);
// 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, // Clicking a tile jumps to the state's subheading under the region
// otherwise to the region it belongs to. // it selects when the state has groups there, otherwise to that
const pickArea = code => { // region. Clicked back to no selection: the state under whichever
const group = groups.find(c => c.area_code === code); // region has its groups, else its first region.
if (group && groupRefs.current[group.id]) { const pickArea = (code, regionId) => {
return scrollListTo(groupRefs.current[group.id]); const id = regionId ?? groups.find(c => c.area_code === code)?.region_id ?? regionsForArea(code)[0]?.id;
} if (!id) return;
const region = regionsForArea(code)[0]; scrollListTo(stateRefs.current[`${id}:${code}`] ?? regionRefs.current[id]);
if (region) scrollListTo(regionRefs.current[region.id]);
}; };
/* The list column, built only when what it shows changes: hovering /* The list column, built only when what it shows changes: hovering
a map tile or legend entry changes `hovered`, which no row reads, a map tile or legend entry changes `hovered`, which no row reads,
so hundreds of groups aren't drawn again for every tile crossed. so hundreds of groups aren't drawn again for every tile crossed. */
hoverInList only touches a ref and a state setter, both stable. */
const list = useMemo(() => { const list = useMemo(() => {
const match = matcher(query); const match = matcher(query);
const block = (region, indent) => { const block = (region, indent) => {
@ -930,13 +943,13 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
key={region.id} key={region.id}
region={region} region={region}
groups={inRegion} groups={inRegion}
subtext={subtextFor(region)} subtext={region.map_note}
indent={indent} indent={indent}
regionRefs={regionRefs} regionRefs={regionRefs}
groupRefs={groupRefs} stateRefs={stateRefs}
selected={selected} selected={selected}
setSelected={setSelected} setSelected={setSelected}
setHovered={hoverInList} setHovered={setHovered}
/> />
); );
}; };
@ -976,7 +989,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
)} )}
</> </>
); );
}, [domestic, international, virtual, groupsIn, subtextFor, selected, query]); }, [domestic, international, virtual, groupsIn, selected, query]);
const shell = children => ( const shell = children => (
<div className="mx-auto px-8 md:px-12" style={{ maxWidth: CONTENT_MAX }}> <div className="mx-auto px-8 md:px-12" style={{ maxWidth: CONTENT_MAX }}>
@ -1023,7 +1036,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
); );
} }
const shared = { selected, setSelected, hovered, setHovered: hoverOnMap }; const shared = { selected, setSelected, hovered, hoveredArea, setHovered: hoverOn };
const onMapIds = new Set(regionAreas.map(a => a.region_id)); const onMapIds = new Set(regionAreas.map(a => a.region_id));
return ( return (
@ -1046,6 +1059,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
domestic={domestic} domestic={domestic}
international={international} international={international}
onMapIds={onMapIds} onMapIds={onMapIds}
onPickRegion={pickRegion}
{...shared} {...shared}
/> />
<p className="text-sm mt-4" style={{ color: MUTED }}> <p className="text-sm mt-4" style={{ color: MUTED }}>