Call local chapters groups, everywhere
The organization kind is 'group', its side table is groups, pages live at /groups/<id> and the Community page's section is #groups. Migration 052 converts existing databases: the kind and the tables whose CHECKs name chapters are rebuilt, the front page count and request category follow, and the site's own /chapters/ and #chapters links in records are rewritten. Request files now go in Requests/Groups on the shared drive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
175a18976d
commit
38aff34c97
42 changed files with 473 additions and 254 deletions
|
|
@ -1,10 +1,10 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
useCommunity
|
||||
|
||||
The chapter map's view of the organization list (OrgList-Map).
|
||||
Regions and chapters are the same table and the same endpoint;
|
||||
The group map's view of the organization list (OrgList-Map).
|
||||
Regions and groups 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.
|
||||
counts per tile, groups grouped by region.
|
||||
|
||||
Two things live elsewhere:
|
||||
|
||||
|
|
@ -24,17 +24,17 @@ import {
|
|||
useOrganizations,
|
||||
} from "./organizations.ts";
|
||||
import {
|
||||
areaForChapter,
|
||||
areaForGroup,
|
||||
buildAreaSlices,
|
||||
countChaptersByArea,
|
||||
countGroupsByArea,
|
||||
} from "../data/mapGrid.ts";
|
||||
|
||||
export function useCommunity() {
|
||||
const regionsQuery = useOrganizations("region");
|
||||
const chaptersQuery = useOrganizations("chapter");
|
||||
const groupsQuery = useOrganizations("group");
|
||||
|
||||
const rawRegions = regionsQuery.organizations;
|
||||
const rawChapters = chaptersQuery.organizations;
|
||||
const rawGroups = groupsQuery.organizations;
|
||||
|
||||
return useMemo(() => {
|
||||
/* ── Regions ───────────────────────────────────────────────
|
||||
|
|
@ -52,18 +52,18 @@ export function useCommunity() {
|
|||
region.areas.map((area) => ({ ...area, region_id: region.id })),
|
||||
);
|
||||
|
||||
/* ── Chapters, each tagged with the tile it lights up ──────
|
||||
/* ── Groups, 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) => ({
|
||||
const groups = rawGroups.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),
|
||||
area_code: areaForGroup(org),
|
||||
}));
|
||||
|
||||
const regionById = Object.fromEntries(regions.map((r) => [r.id, r]));
|
||||
|
|
@ -73,17 +73,17 @@ export function useCommunity() {
|
|||
primary and a remainder, so the SVG never does arithmetic. */
|
||||
const slices = buildAreaSlices(regionAreas, regions);
|
||||
|
||||
const chapterCounts = countChaptersByArea(chapters);
|
||||
const groupCounts = countGroupsByArea(groups);
|
||||
|
||||
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 groupsByRegion = new Map();
|
||||
for (const group of groups) {
|
||||
if (!group.region_id) continue;
|
||||
const list = groupsByRegion.get(group.region_id);
|
||||
if (list) list.push(group);
|
||||
else groupsByRegion.set(group.region_id, [group]);
|
||||
}
|
||||
|
||||
const chaptersIn = (regionId) => chaptersByRegion.get(regionId) ?? [];
|
||||
const groupsIn = (regionId) => groupsByRegion.get(regionId) ?? [];
|
||||
|
||||
/* Sorted by name to match how the page has always shown them,
|
||||
rather than by the sort_order the API returns. */
|
||||
|
|
@ -108,8 +108,8 @@ export function useCommunity() {
|
|||
.filter(Boolean);
|
||||
|
||||
return {
|
||||
loading: regionsQuery.loading || chaptersQuery.loading,
|
||||
error: regionsQuery.error ?? chaptersQuery.error,
|
||||
loading: regionsQuery.loading || groupsQuery.loading,
|
||||
error: regionsQuery.error ?? groupsQuery.error,
|
||||
|
||||
regions,
|
||||
regionAreas,
|
||||
|
|
@ -118,11 +118,11 @@ export function useCommunity() {
|
|||
international,
|
||||
virtual,
|
||||
|
||||
chapters,
|
||||
chaptersIn,
|
||||
groups,
|
||||
groupsIn,
|
||||
|
||||
slices,
|
||||
chapterCounts,
|
||||
groupCounts,
|
||||
regionsForArea,
|
||||
|
||||
areasLabelFor,
|
||||
|
|
@ -130,10 +130,10 @@ export function useCommunity() {
|
|||
};
|
||||
}, [
|
||||
rawRegions,
|
||||
rawChapters,
|
||||
rawGroups,
|
||||
regionsQuery.loading,
|
||||
regionsQuery.error,
|
||||
chaptersQuery.loading,
|
||||
chaptersQuery.error,
|
||||
groupsQuery.loading,
|
||||
groupsQuery.error,
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue