- Text contrast: teal text and button fills use #0f7183 (5.7:1), section accents darkened to pass on white, solid CTA buttons instead of the gradient, footer and subnav text raised to white/65, event and region colours kept on borders and swatches with ink text - Hidden carousel slides and collapsed past events are inert - Admin list rows carry a real link for keyboard use - Mobile menu is a modal dialog: focus, Escape, inert background, above the header - Skip to content link, one focus-visible ring, reduced-motion rule, focus rings on the calendar inputs - Region headings hold their button instead of sitting inside it - font-700 style classes (not Tailwind v4 utilities) replaced with named weights, and the 700/800 font files loaded - Migration 038: alt text for blog covers and schedule graphics; event logos next to their title are decorative - Drop the Church Center script from index.html; Giving loads it itself Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
927 lines
30 KiB
TypeScript
927 lines
30 KiB
TypeScript
import { useEffect, useRef, useState } from "react";
|
||
import { useCommunity } from "../../lib/chapters.ts";
|
||
import { Link } from "react-router-dom";
|
||
import ArrowLink from "../../components/ArrowLink.tsx";
|
||
import { orgLogo } from "../../lib/media.ts";
|
||
import { initialsFor, orgPath } from "../../lib/organizations.ts";
|
||
import { AREAS, AREA_NAMES } from "../../data/mapGrid.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 chapters, 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 colour 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
|
||
<RegionMap>, 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 = "#7a9299";
|
||
const RULE = "#cfe3e7";
|
||
const INK = "#2c4a50";
|
||
const FALLBACK_COLOR = "#4a6b72";
|
||
|
||
/* organizations.color is nullable; an SVG fill left undefined paints
|
||
black, so an uncoloured 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 chapter'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 (
|
||
<div className="mt-4 flex flex-col gap-3" style={{ color: INK }}>
|
||
{blocks.map((block, i) => {
|
||
switch (block.type) {
|
||
case "heading":
|
||
return (
|
||
<h4 key={i} className="text-lg font-extrabold">
|
||
{block.text}
|
||
</h4>
|
||
);
|
||
case "subheading":
|
||
return (
|
||
<h5 key={i} className="font-bold">
|
||
{block.text}
|
||
</h5>
|
||
);
|
||
case "quote":
|
||
return (
|
||
<blockquote
|
||
key={i}
|
||
className="pl-3 italic"
|
||
style={{ borderLeft: `2px solid ${color}` }}
|
||
>
|
||
{block.text}
|
||
</blockquote>
|
||
);
|
||
case "list":
|
||
case "links":
|
||
return (
|
||
<ul key={i} className="list-disc ml-5 flex flex-col gap-1">
|
||
{block.items.map((item, j) => (
|
||
<li key={j}>
|
||
{item.url ? (
|
||
<a
|
||
href={item.url}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
className="font-bold underline"
|
||
style={{ textDecorationColor: color }}
|
||
>
|
||
{item.text}
|
||
</a>
|
||
) : (
|
||
item.text
|
||
)}
|
||
{item.detail && (
|
||
<span className="text-sm" style={{ color: MUTED }}>
|
||
{" "}
|
||
({item.detail})
|
||
</span>
|
||
)}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
);
|
||
case "divider":
|
||
return <hr key={i} style={{ borderColor: RULE }} />;
|
||
default:
|
||
return (
|
||
<p key={i} className="leading-relaxed">
|
||
{block.text}
|
||
</p>
|
||
);
|
||
}
|
||
})}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* ── 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 (
|
||
<g
|
||
onClick={cycle}
|
||
onMouseEnter={() => setHovered(primary.regionId)}
|
||
onMouseLeave={() => setHovered(null)}
|
||
style={{ cursor: "pointer" }}
|
||
opacity={dimmed ? 0.25 : 1}
|
||
className="transition-opacity duration-200"
|
||
>
|
||
<title>
|
||
{AREA_NAMES[code] || code}: {slices.map(s => s.name).join(" / ")}
|
||
{count ? ` · ${count} chapter${count > 1 ? "s" : ""}` : ""}
|
||
</title>
|
||
|
||
<clipPath id={clipId}>
|
||
<rect x={x} y={y} width={width} height={size} rx={14} />
|
||
</clipPath>
|
||
|
||
<g clipPath={`url(#${clipId})`}>
|
||
{slices.map(slice => {
|
||
const h = slice.edge ? size * slice.share : size;
|
||
const top = slice.edge === "bottom" ? y + size - h : y;
|
||
return (
|
||
<rect
|
||
key={slice.regionId}
|
||
x={x}
|
||
y={top}
|
||
width={width}
|
||
height={h}
|
||
fill={colorOf(slice)}
|
||
fillOpacity={opacity}
|
||
className="transition-all duration-200"
|
||
/>
|
||
);
|
||
})}
|
||
</g>
|
||
|
||
<rect
|
||
x={x}
|
||
y={y}
|
||
width={width}
|
||
height={size}
|
||
rx={14}
|
||
fill="none"
|
||
stroke={active ? colorOf(primary) : "#ffffff"}
|
||
strokeOpacity={active ? 1 : 0.55}
|
||
strokeWidth={active ? 4 : 2}
|
||
className="transition-all duration-200"
|
||
/>
|
||
|
||
<text
|
||
x={x + width / 2}
|
||
y={y + size / 2 + 2}
|
||
textAnchor="middle"
|
||
dominantBaseline="middle"
|
||
fontSize={fontSize}
|
||
fontWeight="800"
|
||
fill={count ? "#ffffff" : colorOf(primary)}
|
||
style={{ pointerEvents: "none" }}
|
||
>
|
||
{label || code}
|
||
</text>
|
||
|
||
{count > 0 && (
|
||
<circle
|
||
cx={x + width - 14}
|
||
cy={y + 14}
|
||
r={7}
|
||
fill="#ffffff"
|
||
fillOpacity={0.9}
|
||
style={{ pointerEvents: "none" }}
|
||
/>
|
||
)}
|
||
</g>
|
||
);
|
||
}
|
||
|
||
function RegionMap({ slices, chapterCounts, ...props }: any) {
|
||
const size = TILE - PAD * 2;
|
||
|
||
return (
|
||
<svg
|
||
viewBox={`0 0 ${COLS * TILE} ${ROWS * TILE}`}
|
||
className="w-full h-auto"
|
||
role="group"
|
||
aria-label="Chapters by Unity region"
|
||
>
|
||
{/* States and bands are the same shape, a tile with a span,
|
||
so this is one loop rather than two. */}
|
||
{AREAS.map(area => (
|
||
<Tile
|
||
key={area.code}
|
||
code={area.code}
|
||
label={area.isState ? area.code : area.name}
|
||
x={(area.col - 1) * TILE + PAD}
|
||
y={(area.row - 1) * TILE + PAD}
|
||
size={size}
|
||
width={area.span * TILE - PAD * 2}
|
||
fontSize={area.isState ? 34 : 38}
|
||
slices={slices[area.code] ?? []}
|
||
count={chapterCounts[area.code] ?? 0}
|
||
{...props}
|
||
/>
|
||
))}
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
function LegendButton({ region, selected, setSelected, hovered, setHovered }) {
|
||
const on = selected === region.id || hovered === region.id;
|
||
return (
|
||
<button
|
||
onClick={() => setSelected(selected === region.id ? null : region.id)}
|
||
onMouseEnter={() => setHovered(region.id)}
|
||
onMouseLeave={() => setHovered(null)}
|
||
onFocus={() => setHovered(region.id)}
|
||
onBlur={() => setHovered(null)}
|
||
aria-pressed={selected === region.id}
|
||
className="flex items-center gap-2 py-1.5 px-3 rounded-lg text-sm font-bold transition-all duration-200"
|
||
style={{
|
||
border: `1px solid ${colorOf(region)}`,
|
||
background: on ? colorOf(region) : "transparent",
|
||
color: on ? "#ffffff" : INK,
|
||
opacity: selected && selected !== region.id ? 0.45 : 1,
|
||
}}
|
||
>
|
||
<span
|
||
className="h-2.5 w-2.5 rounded-full"
|
||
style={{ background: on ? "#ffffff" : colorOf(region) }}
|
||
/>
|
||
{region.name}
|
||
</button>
|
||
);
|
||
}
|
||
|
||
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 (
|
||
<div className="mt-6">
|
||
<p className="text-xs uppercase tracking-wide mb-2" style={{ color: MUTED }}>
|
||
{US_TITLE}
|
||
</p>
|
||
<div className="flex flex-wrap gap-2">
|
||
{us.map(r => (
|
||
<LegendButton key={r.id} region={r} {...props} />
|
||
))}
|
||
</div>
|
||
|
||
<div className="h-px my-4" style={{ background: RULE }} />
|
||
|
||
<p className="text-xs uppercase tracking-wide mb-2" style={{ color: MUTED }}>
|
||
{INTL_TITLE}
|
||
</p>
|
||
<div className="flex flex-wrap gap-2 items-center">
|
||
{intl.map(r => (
|
||
<LegendButton key={r.id} region={r} {...props} />
|
||
))}
|
||
{selected && (
|
||
<button
|
||
onClick={() => setSelected(null)}
|
||
className="py-1.5 px-3 rounded-lg text-sm font-bold underline"
|
||
style={{ color: FALLBACK_COLOR }}
|
||
>
|
||
Show all
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function RegionBlock({
|
||
region,
|
||
chapters,
|
||
subtext,
|
||
selected,
|
||
setSelected,
|
||
setHovered,
|
||
indent,
|
||
regionRefs,
|
||
chapterRefs,
|
||
}) {
|
||
const on = selected === region.id;
|
||
|
||
return (
|
||
<div
|
||
ref={el => 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. */}
|
||
<h4 className={`font-extrabold ${indent ? "text-lg" : "text-xl"}`} style={{ color: INK }}>
|
||
<button
|
||
onClick={() => setSelected(on ? null : region.id)}
|
||
onMouseEnter={() => setHovered(region.id)}
|
||
onMouseLeave={() => setHovered(null)}
|
||
aria-expanded={on}
|
||
className="w-full flex items-baseline gap-2 text-left py-2"
|
||
>
|
||
<span
|
||
className="h-3 w-3 rounded-full shrink-0"
|
||
style={{ background: colorOf(region) }}
|
||
/>
|
||
{region.name}
|
||
<span className="text-sm font-normal ml-auto" style={{ color: MUTED }}>
|
||
{chapters.length || "-"}
|
||
</span>
|
||
</button>
|
||
</h4>
|
||
|
||
{subtext && (
|
||
<p className="text-sm mb-2 ml-5 leading-snug" style={{ color: MUTED }}>
|
||
{subtext}
|
||
</p>
|
||
)}
|
||
|
||
{chapters.length === 0 ? (
|
||
<p className="text-sm ml-5 mb-4" style={{ color: MUTED }}>
|
||
No chapters yet. Interested in starting one?
|
||
</p>
|
||
) : (
|
||
<ul className="ml-5 mb-4 flex flex-col gap-3">
|
||
{chapters.map(c => (
|
||
<li
|
||
key={c.id}
|
||
ref={el => chapterRefs && (chapterRefs.current[c.id] = el)}
|
||
className="pl-3 flex items-start gap-3"
|
||
style={{ borderLeft: `2px solid ${colorOf(region)}` }}
|
||
>
|
||
<div className="min-w-0 flex-1">
|
||
<p className="font-bold">{c.name}</p>
|
||
<p className="text-sm" style={{ color: FALLBACK_COLOR }}>
|
||
{c.location_label}
|
||
{c.meets ? ` · ${c.meets}` : ""}
|
||
</p>
|
||
{(c.website || c.email) && (
|
||
<p className="text-sm mt-1 flex gap-4">
|
||
{c.website && (
|
||
<a
|
||
href={c.website}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
className="font-bold underline"
|
||
style={{ color: colorOf(region) }}
|
||
>
|
||
Details
|
||
</a>
|
||
)}
|
||
{c.email && (
|
||
<a
|
||
href={`mailto:${c.email}`}
|
||
className="font-bold underline"
|
||
style={{ color: colorOf(region) }}
|
||
>
|
||
Contact
|
||
</a>
|
||
)}
|
||
</p>
|
||
)}
|
||
</div>
|
||
|
||
{orgPath(c) && (
|
||
<ArrowLink
|
||
to={orgPath(c)}
|
||
label={`${c.name}: chapter page`}
|
||
color={colorOf(region)}
|
||
size="h-8 w-8"
|
||
/>
|
||
)}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* ═══════════════════════════════════════════════════════════════
|
||
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.
|
||
═══════════════════════════════════════════════════════════════ */
|
||
|
||
/* Logo, or the organization's initials when there's no file. */
|
||
function OrgLogo({ org, color, size = "h-14 w-14" }) {
|
||
const [failed, setFailed] = useState(false);
|
||
|
||
if (org.logo && !failed) {
|
||
return (
|
||
<img
|
||
src={orgLogo(org.logo) ?? undefined}
|
||
alt={org.name}
|
||
onError={() => setFailed(true)}
|
||
className={`${size} object-contain rounded-xl shrink-0`}
|
||
/>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<div
|
||
className={`${size} rounded-xl shrink-0 flex items-center justify-center font-extrabold`}
|
||
style={{ border: `1px solid ${color}`, color }}
|
||
aria-label={org.name}
|
||
>
|
||
{initialsFor(org.name)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ChapterCard({ chapter, color, open, onOpen }) {
|
||
return (
|
||
<div
|
||
className="rounded-2xl p-4 flex items-start gap-4 transition-all duration-200"
|
||
style={{
|
||
border: `1px solid ${color}`,
|
||
background: open ? `${color}14` : "transparent",
|
||
}}
|
||
>
|
||
<OrgLogo org={chapter} color={color} />
|
||
|
||
<div className="min-w-0 flex-1">
|
||
<p className="font-bold leading-tight">{chapter.name}</p>
|
||
<p className="text-sm" style={{ color: FALLBACK_COLOR }}>
|
||
{chapter.location_label}
|
||
</p>
|
||
{chapter.meets && (
|
||
<p className="text-sm" style={{ color: MUTED }}>
|
||
{chapter.meets}
|
||
</p>
|
||
)}
|
||
</div>
|
||
|
||
{/* Two controls, two destinations: the chevron opens the
|
||
detail panel in place, the arrow leaves for the chapter's
|
||
own page. Keeping them distinct beats one control that
|
||
does different things depending on where you click. */}
|
||
<div className="shrink-0 flex items-center gap-2">
|
||
<button
|
||
onClick={onOpen}
|
||
aria-expanded={open}
|
||
aria-label={`${open ? "Hide" : "View"} details for ${chapter.name}`}
|
||
className="h-9 w-9 rounded-full flex items-center justify-center transition-transform duration-200 hover:scale-110"
|
||
style={{
|
||
border: `1px solid ${color}`,
|
||
color,
|
||
transform: open ? "rotate(90deg)" : "none",
|
||
}}
|
||
>
|
||
<svg
|
||
viewBox="0 0 24 24"
|
||
className="h-4 w-4"
|
||
fill="none"
|
||
stroke="currentColor"
|
||
strokeWidth="2.5"
|
||
strokeLinecap="round"
|
||
strokeLinejoin="round"
|
||
>
|
||
<path d="M9 6l6 6-6 6" />
|
||
</svg>
|
||
</button>
|
||
|
||
{orgPath(chapter) && (
|
||
<ArrowLink
|
||
to={orgPath(chapter)}
|
||
label={`${chapter.name}: chapter page`}
|
||
color={color}
|
||
/>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ChapterDetail({ chapter, 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 = (chapter.leadership ?? [])
|
||
.map(person =>
|
||
person.title ? `${person.display_name} (${person.title})` : person.display_name
|
||
)
|
||
.join(", ");
|
||
|
||
const rows = [
|
||
["Region", region.name],
|
||
["Where", chapter.venue],
|
||
["Meets", chapter.meets],
|
||
["Led by", leads],
|
||
["Since", chapter.started],
|
||
].filter(([, v]) => v);
|
||
|
||
return (
|
||
<div
|
||
className="rounded-2xl p-6 mb-6"
|
||
style={{ border: `2px solid ${colorOf(region)}`, background: `${colorOf(region)}0f` }}
|
||
>
|
||
<div className="flex items-start gap-4">
|
||
<OrgLogo org={chapter} color={colorOf(region)} size="h-20 w-20" />
|
||
|
||
<div className="min-w-0 flex-1">
|
||
<p className="text-2xl font-extrabold leading-tight">{chapter.name}</p>
|
||
<p style={{ color: FALLBACK_COLOR }}>{chapter.location_label}</p>
|
||
</div>
|
||
|
||
<button
|
||
onClick={onClose}
|
||
aria-label="Close details"
|
||
className="shrink-0 h-8 w-8 rounded-full flex items-center justify-center text-lg font-bold transition-transform duration-200 hover:scale-110"
|
||
style={{ border: `1px solid ${colorOf(region)}`, color: colorOf(region) }}
|
||
>
|
||
×
|
||
</button>
|
||
</div>
|
||
|
||
<Blocks blocks={chapter.blocks} color={colorOf(region)} />
|
||
|
||
{rows.length > 0 && (
|
||
<dl className="mt-4 grid grid-cols-1 sm:grid-cols-2 gap-x-8 gap-y-1 text-sm">
|
||
{rows.map(([label, value]) => (
|
||
<div key={label} className="flex gap-2">
|
||
<dt className="shrink-0" style={{ color: MUTED }}>
|
||
{label}
|
||
</dt>
|
||
<dd className="font-bold" style={{ color: INK }}>
|
||
{value}
|
||
</dd>
|
||
</div>
|
||
))}
|
||
</dl>
|
||
)}
|
||
|
||
<div className="mt-5 flex flex-wrap gap-3">
|
||
{orgPath(chapter) && (
|
||
<Link
|
||
to={orgPath(chapter)!}
|
||
className="py-2 px-5 rounded-xl font-bold text-sm transition-transform duration-200 hover:scale-105"
|
||
style={{ background: colorOf(region), color: "#ffffff" }}
|
||
>
|
||
Chapter page
|
||
</Link>
|
||
)}
|
||
{chapter.website && (
|
||
<a
|
||
href={chapter.website}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
className="py-2 px-5 rounded-xl font-bold text-sm transition-transform duration-200 hover:scale-105"
|
||
style={{ border: `1px solid ${colorOf(region)}`, color: colorOf(region) }}
|
||
>
|
||
Visit site
|
||
</a>
|
||
)}
|
||
|
||
{chapter.email && (
|
||
<a
|
||
href={`mailto:${chapter.email}`}
|
||
className="py-2 px-5 rounded-xl font-bold text-sm transition-transform duration-200 hover:scale-105"
|
||
style={{ border: `1px solid ${colorOf(region)}`, color: colorOf(region) }}
|
||
>
|
||
Get in touch
|
||
</a>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ChapterGrid({ regions, chapters, chaptersIn, subtextFor, openId, setOpenId }) {
|
||
// Only regions that actually have chapters get a grid.
|
||
const populated = regions
|
||
.map(region => ({ region, list: chaptersIn(region.id) }))
|
||
.filter(({ list }) => list.length > 0);
|
||
const empty = regions.filter(region => chaptersIn(region.id).length === 0);
|
||
const openChapter = chapters.find(c => c.id === openId) || null;
|
||
|
||
return (
|
||
<div className="mx-auto px-8 md:px-12" style={{ maxWidth: CONTENT_MAX }}>
|
||
{populated.map(({ region, list }) => {
|
||
const subtext = subtextFor(region);
|
||
return (
|
||
<section key={region.id} className="mb-12">
|
||
<div className="flex items-baseline gap-3 mb-1">
|
||
<span
|
||
className="h-3 w-3 rounded-full shrink-0"
|
||
style={{ background: colorOf(region) }}
|
||
/>
|
||
<h3 className="text-2xl font-extrabold" style={{ color: colorOf(region) }}>
|
||
{region.name}
|
||
</h3>
|
||
<span className="text-sm" style={{ color: MUTED }}>
|
||
{list.length}
|
||
</span>
|
||
</div>
|
||
{subtext && (
|
||
<p className="text-sm mb-5 ml-6" style={{ color: MUTED }}>
|
||
{subtext}
|
||
</p>
|
||
)}
|
||
|
||
{/* Detail panel sits above this region's grid, and only
|
||
when the open chapter belongs to this region. */}
|
||
{openChapter && openChapter.region_id === region.id && (
|
||
<ChapterDetail
|
||
chapter={openChapter}
|
||
region={region}
|
||
onClose={() => setOpenId(null)}
|
||
/>
|
||
)}
|
||
|
||
<div
|
||
className="grid gap-4 items-start"
|
||
style={{
|
||
gridTemplateColumns: "repeat(auto-fill, minmax(min(22rem, 100%), 1fr))",
|
||
}}
|
||
>
|
||
{list.map(c => (
|
||
<ChapterCard
|
||
key={c.id}
|
||
chapter={c}
|
||
color={colorOf(region)}
|
||
open={openId === c.id}
|
||
onOpen={() => setOpenId(openId === c.id ? null : c.id)}
|
||
/>
|
||
))}
|
||
</div>
|
||
</section>
|
||
);
|
||
})}
|
||
|
||
{empty.length > 0 && (
|
||
<p className="text-sm" style={{ color: MUTED }}>
|
||
No chapters yet in {empty.map(r => r.name).join(", ")}. Interested in
|
||
starting one?
|
||
</p>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* The control for the section heading's action bar. */
|
||
export function OrgMapToggle({ view, setView, accent }) {
|
||
const btn = active => ({
|
||
background: active ? accent : "transparent",
|
||
color: active ? "#ffffff" : accent,
|
||
});
|
||
|
||
return (
|
||
<div
|
||
className="inline-flex rounded-xl overflow-hidden shrink-0"
|
||
style={{ border: `1px solid ${accent}` }}
|
||
role="group"
|
||
aria-label="Change how chapters are displayed"
|
||
>
|
||
{[
|
||
["map", "Map"],
|
||
["grid", "Grid"],
|
||
].map(([id, label]) => (
|
||
<button
|
||
key={id}
|
||
onClick={() => setView(id)}
|
||
aria-pressed={view === id}
|
||
className="py-2 px-4 font-bold text-sm transition-colors duration-200"
|
||
style={btn(view === id)}
|
||
>
|
||
{label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
||
const {
|
||
loading,
|
||
error,
|
||
regions,
|
||
regionAreas,
|
||
domestic,
|
||
international,
|
||
virtual,
|
||
chapters,
|
||
chaptersIn,
|
||
slices,
|
||
chapterCounts,
|
||
regionsForArea,
|
||
subtextFor,
|
||
} = useCommunity();
|
||
|
||
const [selected, setSelected] = useState<any>(null);
|
||
const [hovered, setHovered] = useState<any>(null);
|
||
const [openId, setOpenId] = useState<any>(null); // no card open on arrival
|
||
|
||
// The list scrolls itself to whatever the map or legend points at.
|
||
const listRef = useRef<any>(null);
|
||
const regionRefs = useRef<any>({});
|
||
const chapterRefs = useRef<any>({});
|
||
|
||
// 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: "smooth" });
|
||
};
|
||
|
||
// 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 chapter when it has one,
|
||
// otherwise to the region it belongs to.
|
||
const pickArea = code => {
|
||
const chapter = chapters.find(c => c.area_code === code);
|
||
if (chapter && chapterRefs.current[chapter.id]) {
|
||
return scrollListTo(chapterRefs.current[chapter.id]);
|
||
}
|
||
const region = regionsForArea(code)[0];
|
||
if (region) scrollListTo(regionRefs.current[region.id]);
|
||
};
|
||
|
||
const shell = children => (
|
||
<div className="mx-auto px-8 md:px-12" style={{ maxWidth: CONTENT_MAX }}>
|
||
{children}
|
||
</div>
|
||
);
|
||
|
||
if (loading && regions.length === 0) {
|
||
return shell(
|
||
<div className="skeleton" role="status" aria-label="Loading chapters" />
|
||
);
|
||
}
|
||
|
||
if (error && regions.length === 0) {
|
||
return shell(
|
||
<p className="font-semibold" style={{ color: accent }}>
|
||
· Chapters couldn't be loaded just now, please try again shortly ·
|
||
</p>
|
||
);
|
||
}
|
||
|
||
if (view === "grid") {
|
||
return (
|
||
<ChapterGrid
|
||
regions={regions}
|
||
chapters={chapters}
|
||
chaptersIn={chaptersIn}
|
||
subtextFor={subtextFor}
|
||
openId={openId}
|
||
setOpenId={setOpenId}
|
||
/>
|
||
);
|
||
}
|
||
|
||
const shared = { selected, setSelected, hovered, setHovered: hoverOnMap };
|
||
const onMapIds = new Set(regionAreas.map(a => a.region_id));
|
||
|
||
const block = (region, indent) => (
|
||
<RegionBlock
|
||
key={region.id}
|
||
region={region}
|
||
chapters={chaptersIn(region.id)}
|
||
subtext={subtextFor(region)}
|
||
indent={indent}
|
||
regionRefs={regionRefs}
|
||
chapterRefs={chapterRefs}
|
||
{...shared}
|
||
setHovered={hoverInList}
|
||
/>
|
||
);
|
||
|
||
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(
|
||
<div className="grid grid-cols-1 lg:grid-cols-[1.45fr_1fr] gap-10 items-stretch">
|
||
{/* Map */}
|
||
<div>
|
||
<RegionMap
|
||
slices={slices}
|
||
chapterCounts={chapterCounts}
|
||
onPick={pickArea}
|
||
{...shared}
|
||
/>
|
||
<Legend
|
||
domestic={domestic}
|
||
international={international}
|
||
onMapIds={onMapIds}
|
||
{...shared}
|
||
/>
|
||
<p className="text-sm mt-4" style={{ color: MUTED }}>
|
||
A filled tile means a chapter meets there; a two-tone tile is a
|
||
state shared by two Unity regions. Select a region to filter the
|
||
list.
|
||
</p>
|
||
</div>
|
||
|
||
{/* 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. */}
|
||
<div
|
||
ref={listRef}
|
||
className="relative lg:h-0 lg:min-h-full overflow-y-auto pr-2"
|
||
>
|
||
<h3 className="text-xl font-extrabold mb-1" style={{ color: FALLBACK_COLOR }}>
|
||
{US_TITLE}
|
||
</h3>
|
||
{domestic.map(r => block(r, true))}
|
||
|
||
<h3
|
||
className="text-xl font-extrabold mt-6 mb-1 pt-4"
|
||
style={{ color: FALLBACK_COLOR, borderTop: `1px solid ${RULE}` }}
|
||
>
|
||
{INTL_TITLE}
|
||
</h3>
|
||
{international.map(r => block(r, true))}
|
||
|
||
<div className="mt-6 pt-4" style={{ borderTop: `1px solid ${RULE}` }}>
|
||
{virtual.map(r => block(r, false))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)
|
||
);
|
||
}
|