Security: - docx unzip reads each part once (a repeated entry was a zip bomb) - request files must be named for their type (no PDF named .html) - team roster hidden when its organization is unpublished - /people?ids= hides draft organizations, takes 200 ids - v_events takes the first published host and reads event_hosts directly (migration 059, plus an index on person_awards.event_id) - group accounts refused while access groups are off; group sync can't undo a superadmin's disable - 64 KB body limit on login, feedback and csp-report - Drive pick-up races no longer 500; random upload boundary Scalability: - /events filters by scope, host, status and type on the server; Home no longer prefetches every event - /organizations leaves out bodies and leadership; the map's group panel fetches its own - admin lists page with Show more and a real count - content request record search and the newsletter's post list ask the server Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
5.3 KiB
TypeScript
129 lines
5.3 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
||
HOME: /
|
||
|
||
Not a PageShell page: the front page has no title bar, and each
|
||
band draws its own heading in its own style.
|
||
|
||
Driven by the admin's Front page editor through GET /front-page.
|
||
The hero comes first, always. After it, the bands in the order
|
||
the admin dragged them into, minus any they hid. Which component
|
||
draws a band is decided here, in SECTIONS, keyed on the same list
|
||
the CHECK on front_page_sections holds, the database says "retreats,
|
||
third, called National Retreats"; this file says what a retreats
|
||
band looks like.
|
||
|
||
A band with nothing to show draws nothing: the countdown with no
|
||
upcoming event, the numbers with no numbers, the timeline with
|
||
nothing featured, the pathfinder with no paths, the featured band
|
||
with no cards.
|
||
|
||
If /front-page fails, the hero still draws (empty) and the error
|
||
takes the place of the bands, with a retry. There's deliberately
|
||
no default page to fall back to: it would look fine and hide a
|
||
broken server.
|
||
═══════════════════════════════════════════════════════════════ */
|
||
|
||
import { useEffect, type ReactNode } from 'react'
|
||
|
||
import HeroStage from './sections/home/HeroStage.tsx'
|
||
import NextEventCountdown from './sections/home/NextEventCountdown.tsx'
|
||
import RetreatsBand from './sections/home/RetreatsBand.tsx'
|
||
import CalendarBand from './sections/home/CalendarBand.tsx'
|
||
import StatsBand from './sections/home/StatsBand.tsx'
|
||
import FeaturedBand from './sections/home/FeaturedBand.tsx'
|
||
import FeaturedTimelineRail from './sections/home/FeaturedTimelineRail.tsx'
|
||
import Pathfinder from './sections/home/Pathfinder.tsx'
|
||
import { get } from '../lib/api.ts'
|
||
import { documentTitle } from '../lib/site.ts'
|
||
import {
|
||
useFrontPage,
|
||
type FrontPage,
|
||
type FrontPageSection,
|
||
type FrontPageSectionKey,
|
||
} from '../lib/useFrontPage.ts'
|
||
import { FRONT_PAGE_BANDS, bandShows } from '../lib/frontPageBands.ts'
|
||
import './sections/home/home.css'
|
||
|
||
type BandProps = {
|
||
page: FrontPage
|
||
section: FrontPageSection
|
||
title: string
|
||
/** Position among the visible bands, 0 = straight after the hero. */
|
||
position: number
|
||
}
|
||
|
||
/* How each band renders. Its anchor, its heading when the admin
|
||
gave it none, and whether it has anything to draw are
|
||
frontPageBands.ts's, which the nav and footer read too; #connect is
|
||
what the hero's second button points at out of the box. */
|
||
const id = (key: FrontPageSectionKey) => FRONT_PAGE_BANDS[key].id ?? undefined
|
||
|
||
const BANDS: Record<FrontPageSectionKey, (props: BandProps) => ReactNode> = {
|
||
countdown: ({ page, position }) => <NextEventCountdown event={page.countdown!} overlap={position === 0} />,
|
||
retreats: ({ section, title }) => <RetreatsBand id={id('retreats')!} title={title} blurb={section.blurb} />,
|
||
calendar: ({ section, title }) => <CalendarBand id={id('calendar')!} title={title} blurb={section.blurb} />,
|
||
stats: ({ page, section, title }) => (
|
||
<StatsBand id={id('stats')!} title={title} blurb={section.blurb} stats={page.stats} />
|
||
),
|
||
timeline: ({ section, title }) => <FeaturedTimelineRail id={id('timeline')!} title={title} blurb={section.blurb} />,
|
||
connect: ({ page, section, title }) => (
|
||
<Pathfinder id={id('connect')!} title={title} blurb={section.blurb} paths={page.paths} />
|
||
),
|
||
featured: ({ page, section, title }) => (
|
||
<FeaturedBand id={id('featured')!} title={title} blurb={section.blurb} cards={page.featured} />
|
||
),
|
||
}
|
||
|
||
export default function Home() {
|
||
const { data: page, error, reload } = useFrontPage()
|
||
|
||
// The bands below ask for the timeline once the front page has said
|
||
// which of them to show. Start it now, alongside it: api.ts hands the
|
||
// same request to the band when it mounts, so the page waits for one
|
||
// round trip instead of two. Events aren't fetched ahead: each band
|
||
// asks the server for only its own, so there's no one list to start.
|
||
useEffect(() => {
|
||
get('/history').catch(() => {})
|
||
}, [])
|
||
|
||
// Back to the site name when a visitor returns here from a page.
|
||
useEffect(() => {
|
||
document.title = documentTitle()
|
||
}, [])
|
||
|
||
return (
|
||
<>
|
||
<HeroStage hero={page?.hero ?? null} />
|
||
|
||
{error && (
|
||
<section className="px-6 py-24 text-center">
|
||
<p className="text-danger">Couldn’t load the front page. {error}</p>
|
||
<button
|
||
type="button"
|
||
onClick={reload}
|
||
className="mt-4 btn border border-brand px-5 py-2 text-link hover:bg-tint"
|
||
>
|
||
Try again
|
||
</button>
|
||
</section>
|
||
)}
|
||
|
||
{page?.sections.map((section, position) => {
|
||
const render = BANDS[section.section]
|
||
// A key the CHECK has gained since this file was written, or a
|
||
// band with nothing to draw.
|
||
if (!render || !bandShows(page, section.section)) return null
|
||
return (
|
||
<div key={section.section}>
|
||
{render({
|
||
page,
|
||
section,
|
||
title: section.title || FRONT_PAGE_BANDS[section.section].title,
|
||
position,
|
||
})}
|
||
</div>
|
||
)
|
||
})}
|
||
</>
|
||
)
|
||
}
|