Tidy the structure the audit found
- The colour defaults have one source, server/src/themeDefaults.js, read by the server and the admin; the build stops if src/index.css disagrees with it - server/src/admin-schema.js split into admin-schema/, one file per entity plus columns.js (the registry checked identical) - loadOwned() in shape.js replaces the same three loads on four detail routes (every public route checked identical); one NO_STORE - One OrgLogo component for the org lists and the chapter map; an organization's own page now shows the same initials as the lists - One localISO() for the viewer's calendar day, in place of three - Boot refuses a descriptor dropdown value the table's CHECK doesn't allow, instead of it failing on save - Deleted the unused Other.tsx and white-background logo; chapters.ts is useCommunity.ts; isSuper() in the Panel; stale comments and docs corrected Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
048c7599ce
commit
f934b1dd93
44 changed files with 1187 additions and 1170 deletions
139
src/lib/useCommunity.ts
Normal file
139
src/lib/useCommunity.ts
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
useCommunity
|
||||
|
||||
The chapter map's view of the organization list (OrgList-Map).
|
||||
Regions and chapters are the same table and the same endpoint;
|
||||
this hook reshapes them into what a map needs, slices per tile,
|
||||
counts per tile, chapters grouped by region.
|
||||
|
||||
Two things live elsewhere:
|
||||
|
||||
the tile grid src/data/mapGrid.ts. Where a state sits never
|
||||
changes, so it isn't worth a round trip.
|
||||
|
||||
the fetch src/lib/organizations.ts. One endpoint for
|
||||
every kind, so a section listing regions and
|
||||
a section listing partners read alike.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useMemo } from "react";
|
||||
|
||||
import {
|
||||
areasSentence,
|
||||
byName,
|
||||
useOrganizations,
|
||||
} from "./organizations.ts";
|
||||
import {
|
||||
areaForChapter,
|
||||
buildAreaSlices,
|
||||
countChaptersByArea,
|
||||
} from "../data/mapGrid.ts";
|
||||
|
||||
export function useCommunity() {
|
||||
const regionsQuery = useOrganizations("region");
|
||||
const chaptersQuery = useOrganizations("chapter");
|
||||
|
||||
const rawRegions = regionsQuery.organizations;
|
||||
const rawChapters = chaptersQuery.organizations;
|
||||
|
||||
return useMemo(() => {
|
||||
/* ── Regions ───────────────────────────────────────────────
|
||||
scope and map_note are lifted out of `details` so the rest
|
||||
of the app doesn't have to know they're kind-specific. */
|
||||
const regions = rawRegions.map((org) => ({
|
||||
...org,
|
||||
scope: org.details?.scope ?? null,
|
||||
map_note: org.details?.map_note ?? null,
|
||||
areas: org.details?.areas ?? [],
|
||||
}));
|
||||
|
||||
// Flat, because buildAreaSlices takes it that way.
|
||||
const regionAreas = regions.flatMap((region) =>
|
||||
region.areas.map((area) => ({ ...area, region_id: region.id })),
|
||||
);
|
||||
|
||||
/* ── Chapters, each tagged with the tile it lights up ──────
|
||||
The database stores a real address; which square that maps
|
||||
to is a rendering question, answered here once rather than
|
||||
at every call site. */
|
||||
const chapters = rawChapters.map((org) => ({
|
||||
...org,
|
||||
region_id: org.details?.region_id ?? null,
|
||||
region_name: org.details?.region_name ?? null,
|
||||
region_color: org.details?.region_color ?? null,
|
||||
meets: org.details?.meets ?? null,
|
||||
started: org.details?.started ?? null,
|
||||
area_code: areaForChapter(org),
|
||||
}));
|
||||
|
||||
const regionById = Object.fromEntries(regions.map((r) => [r.id, r]));
|
||||
|
||||
/* { WA: [{ regionId, name, color, share, edge, note }], ... }
|
||||
California comes back as two half slices rather than a
|
||||
primary and a remainder, so the SVG never does arithmetic. */
|
||||
const slices = buildAreaSlices(regionAreas, regions);
|
||||
|
||||
const chapterCounts = countChaptersByArea(chapters);
|
||||
|
||||
const chaptersByRegion = new Map();
|
||||
for (const chapter of chapters) {
|
||||
if (!chapter.region_id) continue;
|
||||
const list = chaptersByRegion.get(chapter.region_id);
|
||||
if (list) list.push(chapter);
|
||||
else chaptersByRegion.set(chapter.region_id, [chapter]);
|
||||
}
|
||||
|
||||
const chaptersIn = (regionId) => chaptersByRegion.get(regionId) ?? [];
|
||||
|
||||
/* Sorted by name to match how the page has always shown them,
|
||||
rather than by the sort_order the API returns. */
|
||||
const domestic = regions.filter((r) => r.scope === "domestic").sort(byName);
|
||||
const international = regions
|
||||
.filter((r) => r.scope === "international")
|
||||
.sort(byName);
|
||||
const virtual = regions.filter((r) => r.scope === "virtual");
|
||||
|
||||
const areasLabelFor = (regionId) =>
|
||||
areasSentence(regionById[regionId]?.areas ?? []);
|
||||
|
||||
const subtextFor = (region) => {
|
||||
const label = areasLabelFor(region.id);
|
||||
if (label && region.map_note) return `${label} · ${region.map_note}`;
|
||||
return label || region.map_note || "";
|
||||
};
|
||||
|
||||
const regionsForArea = (areaCode) =>
|
||||
(slices[areaCode] ?? [])
|
||||
.map((slice) => regionById[slice.regionId])
|
||||
.filter(Boolean);
|
||||
|
||||
return {
|
||||
loading: regionsQuery.loading || chaptersQuery.loading,
|
||||
error: regionsQuery.error ?? chaptersQuery.error,
|
||||
|
||||
regions,
|
||||
regionAreas,
|
||||
regionById,
|
||||
domestic,
|
||||
international,
|
||||
virtual,
|
||||
|
||||
chapters,
|
||||
chaptersIn,
|
||||
|
||||
slices,
|
||||
chapterCounts,
|
||||
regionsForArea,
|
||||
|
||||
areasLabelFor,
|
||||
subtextFor,
|
||||
};
|
||||
}, [
|
||||
rawRegions,
|
||||
rawChapters,
|
||||
regionsQuery.loading,
|
||||
regionsQuery.error,
|
||||
chaptersQuery.loading,
|
||||
chaptersQuery.error,
|
||||
]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue