NGU-Web/src/pages/SitePage.tsx
Zaldimmar 222c9e69a2 Third audit, UI half; side nav on top; request button colors
- Event cards: lazy -640 photo, only nearby slides drawn, a counter
  past 12 events, past grid paged with Show more
- Community map: search over list and grid, 12 per region then Show
  all, list no longer redrawn on hover
- People tiles: one clip check for the list, Show all past 30
- Person pages: 6 events and posts then Show all; excerpts load only
  the first paragraph
- Admin: filter box on long pickers and the QR select, options sent
  per form, Media thumbnails from the small copy, debounced searches
  that drop stale answers
- Pages show their last data while refreshing after the cache TTL
- Side nav stacks above page content (the carousel arrows)
- No event request button on National Retreats; request buttons take
  their section's accent
- Version v1.11.1-audit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 19:09:21 -05:00

191 lines
7.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ═══════════════════════════════════════════════════════════════
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. */
/* Event sections in these scopes offer no Request button. */
const NO_EVENT_REQUEST_SCOPES = ['national']
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,
// NGU's own national retreats aren't the public's to add.
request: NO_EVENT_REQUEST_SCOPES.includes(section.scope_id ?? '')
? undefined
: { 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>
)
}