/* ═══════════════════════════════════════════════════════════════ SITE PAGE: /community, /retreats, /resources, /organization, /history Each is a list of sections built in the admin (Pages → the page, GET /site-pages/:id). A section is its heading, then its own content blocks, then its preset if it has one: a prebuilt part of the site, from PRESETS below. A section with neither says it's coming (ComingSoon) rather than showing a heading over nothing. The title and intro are site.json's, which also gives the search metadata. ═══════════════════════════════════════════════════════════════ */ import { useEffect } from 'react' import { useLocation } from 'react-router-dom' import PageShell from '../components/PageShell.tsx' import ComingSoon from '../components/ComingSoon.tsx' import ContentBlocks from '../components/ContentBlocks.tsx' import { sitePage } from '../lib/site.ts' import { useSectionManifest } from '../lib/sections.tsx' import { useSitePage, type SitePageSection } from '../lib/useSitePages.ts' import { useHistory } from '../lib/useHistory.ts' import { HISTORY_DECADES } from '../data/historyDecades.ts' import { ACCENTS, BRAND } from '../lib/color.ts' import { scrollBehavior } from '../lib/motion.ts' import OrgListMap, { OrgMapToggle } from './sections/OrgList-Map.tsx' import OrgListVertical from './sections/OrgList-Vertical.tsx' import OrgListCards from './sections/OrgList-Card.tsx' import EventListCards, { EventCardsToggle } from './sections/EventList-Cards.tsx' import CommunityBlog from './sections/CommunityBlog.tsx' import HistoryTimeline from './sections/history/HistoryTimeline.tsx' /* Year the program starts: decades ending before it get the pre-program look on the timeline. */ const PROGRAM_START_YEAR = 2000 /* Each preset: the view it draws, its fixed props, its toggle (the section's own view picks the first one) and its Request button. The keys are the CHECK list on page_sections.preset. */ const PRESETS: Record Record> = { community_blog: () => ({ Component: CommunityBlog, request: { type: 'blog', label: 'Write for the blog' }, }), group_map: (section) => ({ Component: OrgListMap, request: { type: 'group', label: 'Add or update a group' }, views: { options: ['map', 'grid'], default: section.view === 'grid' ? 'grid' : 'map', Toggle: OrgMapToggle }, }), region_list: () => ({ Component: OrgListVertical, request: { type: 'region', label: 'Request a region update' }, props: { kind: 'region', pageLabel: 'Region page', groupBy: (org: any) => org.details?.scope, groups: [ { key: 'domestic', title: 'US Unity Regions' }, { key: 'international', title: 'International Unity Regions' }, ], }, }), partner_list: () => ({ Component: OrgListCards, request: { type: 'partner', label: 'Request a partner listing' }, props: { kind: 'partner', pageLabel: 'Partner page', empty: '· Partner organizations coming soon ·' }, }), events: (section) => ({ Component: EventListCards, request: { type: 'event', label: 'Add or update an event' }, props: { scope: section.scope_id ?? undefined, type: section.event_type ?? undefined }, views: { options: ['carousel', 'grid'], default: section.view === 'grid' ? 'grid' : 'carousel', Toggle: EventCardsToggle, }, }), timeline: () => ({ Component: Timeline }), } export default function SitePage({ id }: { id: string }) { const PAGE = sitePage(`/${id}`) const { data: page, loading, error } = useSitePage(id) if (page) return return ( <>
{error ? (

Couldn’t load this page right now.

) : ( loading &&
)}
) } /* Its own component so the manifest, which seeds each toggle's view once, sees the loaded sections. */ function Sections({ title, intro, sections }: { title: string; intro?: string; sections: SitePageSection[] }) { // Layout scrolls to a link's #section on arrival, before the // sections have loaded; this does it again once they're here. const { hash } = useLocation() useEffect(() => { if (hash) document.getElementById(decodeURIComponent(hash.slice(1)))?.scrollIntoView({ behavior: scrollBehavior() }) }, [hash]) const manifest = useSectionManifest( sections.map((section) => { const accent = ACCENTS[section.accent ?? 'teal'] ?? BRAND const preset = section.preset ? PRESETS[section.preset]?.(section) : null return { id: section.anchor, title: section.title, blurb: section.blurb ?? undefined, accent, ...preset, // Blocks, then the preset under them. Component: SectionBody, props: { blocks: section.blocks, title: section.title, Preset: preset?.Component, presetProps: preset?.props }, } }), ) return } function SectionBody({ blocks, title, Preset, presetProps, ...rest }: any) { if (!blocks.length && !Preset) return return ( <> {blocks.length > 0 && (
)} {Preset && } ) } function Timeline({ accent = BRAND }: { accent?: string }) { const { items, loading, error, reload } = useHistory() // The custom properties bind the timeline to this section's accent // and the page's surface, which the rail must match or it shows // through the year dots. return (
{loading ? (

Loading the timeline…

) : error ? ( // A history page that silently renders nothing looks like an // organization with no history: say so, and offer a retry.

Couldn’t load the timeline. {error}

) : ( )}
) }