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
250
src/pages/sections/home/FeaturedTimelineRail.tsx
Normal file
250
src/pages/sections/home/FeaturedTimelineRail.tsx
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
FEATURED TIMELINE RAIL
|
||||
|
||||
The history page's featured entries, sideways: oldest on the
|
||||
left, so scrolling right moves forward through time. A line runs
|
||||
under the cards with a dot per entry, and a year label wherever
|
||||
the year changes. The last card goes to the full history.
|
||||
|
||||
Featured is the admin's call — timeline_entries.is_featured,
|
||||
"shown large" on the history page. Nothing else is filtered
|
||||
here; /history has already decided what's public.
|
||||
|
||||
Scrolling is native — touch, trackpad, shift-wheel — with
|
||||
scroll-snap so it settles on a card. A mouse can also drag it, and
|
||||
the arrow buttons step one card. A drag that moved more than a few
|
||||
pixels swallows the click it ends in, so letting go over a card
|
||||
doesn't open it.
|
||||
|
||||
Nothing featured, and the section doesn't render at all.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useRef, useState, type PointerEvent as ReactPointerEvent } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import HomeLink from './HomeLink.tsx'
|
||||
import { useHistory } from '../../../lib/useHistory.ts'
|
||||
import { hrefFor, logoSrc } from '../../../lib/timelineRefs.ts'
|
||||
import { MONTH_LABELS, type TimelineItem } from '../../../lib/timeline.ts'
|
||||
|
||||
const TEAL = '#138ba0'
|
||||
const DRAG_SLOP = 6
|
||||
|
||||
type RailProps = { id: string; title: string; blurb?: string | null }
|
||||
|
||||
export default function FeaturedTimelineRail({ id, title, blurb }: RailProps) {
|
||||
const { items, loading, error, reload } = useHistory()
|
||||
const featured = items
|
||||
.filter((item) => item.featured)
|
||||
.sort((a, b) => a.date.localeCompare(b.date))
|
||||
|
||||
const railRef = useRef<HTMLOListElement>(null)
|
||||
const drag = useRef({ x: 0, left: 0, moved: false, active: false })
|
||||
const [dragging, setDragging] = useState(false)
|
||||
|
||||
if (!loading && !error && featured.length === 0) return null
|
||||
|
||||
const step = (direction: number) => {
|
||||
const rail = railRef.current
|
||||
const card = rail?.querySelector('li')
|
||||
if (!rail || !card) return
|
||||
rail.scrollBy({ left: direction * (card.clientWidth + 24), behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const onPointerDown = (e: ReactPointerEvent<HTMLOListElement>) => {
|
||||
if (e.pointerType !== 'mouse' || !railRef.current) return
|
||||
drag.current = { x: e.clientX, left: railRef.current.scrollLeft, moved: false, active: true }
|
||||
}
|
||||
|
||||
const onPointerMove = (e: ReactPointerEvent<HTMLOListElement>) => {
|
||||
const d = drag.current
|
||||
if (!d.active || !railRef.current) return
|
||||
const dx = e.clientX - d.x
|
||||
if (!d.moved && Math.abs(dx) > DRAG_SLOP) {
|
||||
d.moved = true
|
||||
setDragging(true)
|
||||
railRef.current.setPointerCapture(e.pointerId)
|
||||
}
|
||||
if (d.moved) railRef.current.scrollLeft = d.left - dx
|
||||
}
|
||||
|
||||
const endDrag = () => {
|
||||
drag.current.active = false
|
||||
setDragging(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<section id={id} className="overflow-hidden py-24" style={{ background: '#f4faf7' }}>
|
||||
<div className="mx-auto flex max-w-6xl flex-wrap items-end gap-6 px-6">
|
||||
<div>
|
||||
<h2 className="font-display text-4xl font-extrabold text-[#073d4a] md:text-5xl">
|
||||
{title}
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-xl text-lg text-[#4a6b72]">{blurb}</p>}
|
||||
</div>
|
||||
|
||||
{featured.length > 1 && (
|
||||
<div className="ml-auto flex gap-2">
|
||||
{[
|
||||
[-1, '‹', 'Earlier'],
|
||||
[1, '›', 'Later'],
|
||||
].map(([direction, glyph, label]) => (
|
||||
<button
|
||||
key={label}
|
||||
type="button"
|
||||
onClick={() => step(direction as number)}
|
||||
aria-label={label as string}
|
||||
className="flex h-12 w-12 items-center justify-center rounded-full border text-2xl transition-colors hover:bg-white"
|
||||
style={{ borderColor: TEAL, color: TEAL }}
|
||||
>
|
||||
{glyph}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<p className="mx-auto mt-10 max-w-6xl px-6 text-[#b3261e]">
|
||||
Couldn’t load the timeline. {error}{' '}
|
||||
<button type="button" onClick={reload} className="underline">
|
||||
Try again
|
||||
</button>
|
||||
</p>
|
||||
) : loading ? (
|
||||
<div className="mx-auto mt-12 flex max-w-6xl gap-6 px-6" aria-hidden="true">
|
||||
{[0, 1, 2].map((i) => (
|
||||
<div key={i} className="h-72 w-80 shrink-0 animate-pulse rounded-3xl bg-white" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<ol
|
||||
ref={railRef}
|
||||
className={`hp-rail mt-12 flex gap-6 overflow-x-auto px-6 pb-4 md:px-[max(1.5rem,calc((100vw-72rem)/2+1.5rem))] ${
|
||||
dragging ? 'hp-rail--dragging' : ''
|
||||
}`}
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerMove={onPointerMove}
|
||||
onPointerUp={endDrag}
|
||||
onPointerCancel={endDrag}
|
||||
// Links and images are natively draggable, and a native
|
||||
// drag cancels the pointer stream this relies on.
|
||||
onDragStart={(e) => e.preventDefault()}
|
||||
onClickCapture={(e) => {
|
||||
if (drag.current.moved) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
drag.current.moved = false
|
||||
}
|
||||
}}
|
||||
>
|
||||
{featured.map((item, index) => (
|
||||
<li key={item.id} className="w-[19rem] shrink-0 md:w-[22rem]">
|
||||
<RailCard
|
||||
item={item}
|
||||
showYear={index === 0 || year(item) !== year(featured[index - 1])}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
|
||||
<li className="w-[19rem] shrink-0 md:w-[22rem]">
|
||||
<div className="flex h-full flex-col">
|
||||
<div className="h-12" />
|
||||
<Link
|
||||
to="/history"
|
||||
draggable={false}
|
||||
className="flex flex-1 flex-col justify-center rounded-3xl p-8 text-white transition-transform duration-300 hover:-translate-y-1"
|
||||
style={{ background: `linear-gradient(150deg, ${TEAL}, #073d4a)` }}
|
||||
>
|
||||
<span className="font-display text-2xl font-extrabold">The whole story</span>
|
||||
<span className="mt-2 text-white/75">Every year, every milestone.</span>
|
||||
<span className="mt-6 font-semibold">See the full history →</span>
|
||||
</Link>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
const year = (item: TimelineItem) => item.date.slice(0, 4)
|
||||
|
||||
/* "June 2014", "2014", "12 June 2014" — only as much as precision
|
||||
says is true. */
|
||||
function dateLabel(item: TimelineItem): string {
|
||||
const [y, m, d] = item.date.split('-')
|
||||
const month = m ? MONTH_LABELS[Number(m) - 1] : null
|
||||
if (item.precision === 'day' && d && month) return `${Number(d)} ${month} ${y}`
|
||||
if (item.precision !== 'year' && month) return `${month} ${y}`
|
||||
return y
|
||||
}
|
||||
|
||||
function RailCard({ item, showYear }: { item: TimelineItem; showYear: boolean }) {
|
||||
const href = hrefFor(item)
|
||||
const logo = logoSrc(item)
|
||||
|
||||
const body = (
|
||||
<>
|
||||
{logo && (
|
||||
<img
|
||||
src={logo}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
draggable={false}
|
||||
className="mb-5 h-14 w-14 object-contain"
|
||||
/>
|
||||
)}
|
||||
<p className="text-xs font-bold uppercase tracking-[0.2em]" style={{ color: TEAL }}>
|
||||
{dateLabel(item)}
|
||||
</p>
|
||||
<p className="mt-2 font-display text-xl font-bold leading-snug text-[#073d4a]">
|
||||
{item.title}
|
||||
</p>
|
||||
{item.meta && <p className="mt-1 text-sm text-[#4a6b72]">{item.meta}</p>}
|
||||
{item.blurb && (
|
||||
<p className="mt-3 line-clamp-4 text-sm leading-relaxed text-[#4a6b72]">{item.blurb}</p>
|
||||
)}
|
||||
{href && (
|
||||
<span className="mt-auto pt-5 text-sm font-semibold" style={{ color: TEAL }}>
|
||||
Read more →
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
||||
const card =
|
||||
'flex flex-1 flex-col rounded-3xl border border-[#138ba0]/15 bg-white p-7 shadow-sm'
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
{/* The line, its dot, and the year where it changes. */}
|
||||
<div className="relative mb-4 h-8">
|
||||
<div className="absolute inset-x-[-1.5rem] top-1/2 h-px bg-[#138ba0]/30" />
|
||||
<span
|
||||
className="absolute left-0 top-1/2 h-3 w-3 -translate-y-1/2 rounded-full border-2 bg-white"
|
||||
style={{ borderColor: TEAL }}
|
||||
/>
|
||||
{showYear && (
|
||||
<span
|
||||
className="absolute left-5 top-1/2 -translate-y-1/2 rounded-full px-3 py-0.5 font-display text-sm font-bold text-white"
|
||||
style={{ background: TEAL }}
|
||||
>
|
||||
{year(item)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{href ? (
|
||||
<HomeLink
|
||||
url={href}
|
||||
className={`${card} transition-all duration-300 hover:-translate-y-1 hover:shadow-xl`}
|
||||
>
|
||||
{body}
|
||||
</HomeLink>
|
||||
) : (
|
||||
<div className={card}>{body}</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue