Migration 058 turns the organization_details preset into the section's own blocks and drops it from page_sections' CHECK. The side nav is placed in the left margin beside the 72rem content, from 88rem screens up, so sections stay where they'd be without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
185 lines
7.2 KiB
TypeScript
185 lines
7.2 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
||
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<string, (section: SitePageSection) => Record<string, any>> = {
|
||
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 <Sections title={PAGE.title} intro={PAGE.description} sections={page.sections} />
|
||
|
||
return (
|
||
<>
|
||
<PageShell title={PAGE.title} intro={PAGE.description} sections={[]} />
|
||
<div className="mx-auto max-w-6xl px-6 py-20">
|
||
{error ? (
|
||
<p className="text-danger">Couldn’t load this page right now.</p>
|
||
) : (
|
||
loading && <div className="skeleton !min-h-40" aria-label="Loading the page" />
|
||
)}
|
||
</div>
|
||
</>
|
||
)
|
||
}
|
||
|
||
/* 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 <PageShell sideNav title={title} intro={intro} sections={manifest} />
|
||
}
|
||
|
||
function SectionBody({ blocks, title, Preset, presetProps, ...rest }: any) {
|
||
if (!blocks.length && !Preset) return <ComingSoon what={`our ${title}`} />
|
||
return (
|
||
<>
|
||
{blocks.length > 0 && (
|
||
<div className={`mx-auto max-w-6xl px-6 ${Preset ? 'mb-12' : ''}`}>
|
||
<ContentBlocks blocks={blocks} accent={rest.accent} />
|
||
</div>
|
||
)}
|
||
{Preset && <Preset {...presetProps} {...rest} />}
|
||
</>
|
||
)
|
||
}
|
||
|
||
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 (
|
||
<div
|
||
className="mx-auto max-w-6xl px-6"
|
||
style={{ '--tl-accent': accent, '--tl-surface': 'var(--color-surface)' } as React.CSSProperties}
|
||
>
|
||
{loading ? (
|
||
<p className="py-12 text-muted" role="status">
|
||
Loading the timeline…
|
||
</p>
|
||
) : error ? (
|
||
// A history page that silently renders nothing looks like an
|
||
// organization with no history: say so, and offer a retry.
|
||
<div className="py-12">
|
||
<p className="text-danger">Couldn’t load the timeline. {error}</p>
|
||
<button
|
||
type="button"
|
||
onClick={reload}
|
||
className="btn mt-3 border border-brand px-4 py-1.5 text-sm text-link transition-colors hover:bg-tint"
|
||
>
|
||
Try again
|
||
</button>
|
||
</div>
|
||
) : (
|
||
<HistoryTimeline
|
||
items={items}
|
||
decades={HISTORY_DECADES}
|
||
direction="desc"
|
||
programStartYear={PROGRAM_START_YEAR}
|
||
/>
|
||
)}
|
||
</div>
|
||
)
|
||
}
|