Replace the front page with an admin-driven home
The home page is rebuilt from scratch and configured from a new Front page tab in the admin, backed by migration 017 and served by GET /api/front-page. Hero: brand, photos (crossfading slideshow with progress and pause) or livestream (YouTube/Facebook/Vimeo embed with a LIVE badge), switched by hand. After it, bands the admin can reorder, retitle or hide: a countdown to the next event (series-aware), the National Retreats carousel, a numbers band (typed in or counted from the database), a horizontal rail of featured timeline entries, and a "Find your way in" pathfinder replacing the old connect section. The CRUD engine gains a `singleton` flag: the entity has one row, made by its migration, and create and delete are refused. The list screen opens that row and the editor drops the slug, back link and delete. shapeSeries moves to shape.js so /front-page can share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b4b013209b
commit
6a69084de2
25 changed files with 2299 additions and 494 deletions
127
src/pages/sections/home/StatsBand.tsx
Normal file
127
src/pages/sections/home/StatsBand.tsx
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
STATS BAND
|
||||
|
||||
The numbers from the admin's Front page editor, counted by the
|
||||
API or typed in. Each one counts up from zero the first time the
|
||||
band scrolls into view; a value that isn't a plain number
|
||||
("Since 2004", "Coast to coast") just appears.
|
||||
|
||||
Reduced motion skips the count and shows the number.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
import type { FrontPageStat } from '../../../lib/useFrontPage.ts'
|
||||
|
||||
const COUNT_MS = 1400
|
||||
|
||||
type StatsBandProps = {
|
||||
id: string
|
||||
title: string
|
||||
blurb?: string | null
|
||||
stats: FrontPageStat[]
|
||||
}
|
||||
|
||||
export default function StatsBand({ id, title, blurb, stats }: StatsBandProps) {
|
||||
const ref = useRef<HTMLElement>(null)
|
||||
const [seen, setSeen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const el = ref.current
|
||||
if (!el || seen) return
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
if (entry.isIntersecting) {
|
||||
setSeen(true)
|
||||
observer.disconnect()
|
||||
}
|
||||
},
|
||||
{ threshold: 0.35 },
|
||||
)
|
||||
observer.observe(el)
|
||||
return () => observer.disconnect()
|
||||
}, [seen])
|
||||
|
||||
return (
|
||||
<section
|
||||
id={id}
|
||||
ref={ref}
|
||||
className="relative overflow-hidden py-24"
|
||||
style={{ background: 'linear-gradient(160deg, #073d4a 0%, #04262e 70%)' }}
|
||||
>
|
||||
<div
|
||||
className="pointer-events-none absolute -left-40 -top-40 h-[32rem] w-[32rem] rounded-full opacity-25 blur-3xl"
|
||||
style={{ background: '#10d48a' }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
<div className="relative mx-auto max-w-6xl px-6">
|
||||
<h2 className="font-display text-sm font-bold uppercase tracking-[0.3em] text-[#9fe7d0]">
|
||||
{title}
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-2xl text-white/70">{blurb}</p>}
|
||||
|
||||
<dl className="mt-12 grid grid-cols-2 gap-x-8 gap-y-14 md:grid-cols-4">
|
||||
{stats.map((stat, index) => (
|
||||
<div
|
||||
key={`${stat.label}-${index}`}
|
||||
className={`hp-stat border-l border-white/15 pl-6 ${seen ? 'hp-stat--in' : ''}`}
|
||||
style={{ transitionDelay: `${index * 120}ms` }}
|
||||
>
|
||||
<dd className="font-display text-5xl font-extrabold leading-none text-white md:text-6xl">
|
||||
<CountUp value={stat.value} run={seen} />
|
||||
{stat.suffix && <span className="text-[#9fe7d0]">{stat.suffix}</span>}
|
||||
</dd>
|
||||
<dt className="mt-3 text-sm font-semibold uppercase tracking-widest text-white/70">
|
||||
{stat.label}
|
||||
</dt>
|
||||
{stat.note && <p className="mt-1 text-sm text-white/50">{stat.note}</p>}
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/* "1,200" counts to 1,200 and keeps its comma; "12.5" keeps its
|
||||
decimal. Anything that isn't just a number renders as given. */
|
||||
function CountUp({ value, run }: { value: string; run: boolean }) {
|
||||
const numeric = /^\d[\d,]*(\.\d+)?$/.test(value)
|
||||
const target = numeric ? Number(value.replace(/,/g, '')) : 0
|
||||
const decimals = value.split('.')[1]?.length ?? 0
|
||||
const grouped = value.includes(',')
|
||||
|
||||
const reduced =
|
||||
typeof window !== 'undefined' &&
|
||||
window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
||||
|
||||
const [shown, setShown] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (!numeric || !run || reduced) return
|
||||
let frame = 0
|
||||
const start = performance.now()
|
||||
const tick = (t: number) => {
|
||||
const p = Math.min(1, (t - start) / COUNT_MS)
|
||||
// Ease out: fast at first, settling onto the number.
|
||||
setShown(target * (1 - Math.pow(1 - p, 3)))
|
||||
if (p < 1) frame = requestAnimationFrame(tick)
|
||||
}
|
||||
frame = requestAnimationFrame(tick)
|
||||
return () => cancelAnimationFrame(frame)
|
||||
}, [numeric, run, reduced, target])
|
||||
|
||||
if (!numeric) return <>{value}</>
|
||||
|
||||
const n = reduced || !run ? (run ? target : 0) : shown
|
||||
return (
|
||||
<span className="tabular-nums">
|
||||
{n.toLocaleString(undefined, {
|
||||
minimumFractionDigits: decimals,
|
||||
maximumFractionDigits: decimals,
|
||||
useGrouping: grouped || target >= 10_000,
|
||||
})}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue