Page editors: Retreats, Community, Resources, Organization and History built from sections
Each page is now a list of sections edited in Admin → Pages: a title (30 characters at most, for the side nav), URL ID, blurb and accent, its own content blocks, and an optional preset (Community blog, groups map, region list, partner cards, events, timeline, NGU's details). Migration 056 seeds every page as the code drew it and moves the Organization editor's blocks and volunteering into its sections. The Community blog's settings move into the Community editor. The header, footer and side nav read each page's sections from the API. The admin engine reads and writes nested collections to any depth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4a1d6fd6e9
commit
9daf7b1a4f
29 changed files with 972 additions and 938 deletions
216
src/pages/SitePage.tsx
Normal file
216
src/pages/SitePage.tsx
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
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 { ORGANIZATION_DETAILS } from '../data/organizationDetails.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 }),
|
||||
organization_details: () => ({ Component: OrganizationDetails }),
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
/* NGU's address, nonprofit status and email (src/data/organizationDetails.ts). */
|
||||
function OrganizationDetails() {
|
||||
const details = ORGANIZATION_DETAILS
|
||||
return (
|
||||
<div className="mx-auto grid max-w-6xl gap-8 px-6 md:grid-cols-2">
|
||||
<div className="space-y-3 text-body">
|
||||
<address className="not-italic leading-relaxed">
|
||||
{details.street}
|
||||
<br />
|
||||
{details.cityLine}
|
||||
<br />
|
||||
<span className="text-sm text-muted">({details.addressNote})</span>
|
||||
</address>
|
||||
<p className="text-sm text-muted">
|
||||
{details.nonprofit} Tax ID: {details.taxId}.
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<a
|
||||
href={`mailto:${details.email}`}
|
||||
className="btn inline-block border border-link px-6 py-2.5 text-link transition-colors hover:bg-tint"
|
||||
>
|
||||
{details.email}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue