/* ═══════════════════════════════════════════════════════════════ 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 { ArrowRight, CaretRight, CaretLeft } from '@phosphor-icons/react'; 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' import { accentText, BRAND } from '../../../lib/color.ts' import { scrollBehavior } from '../../../lib/motion.ts'; 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(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: scrollBehavior() }) } const onPointerDown = (e: ReactPointerEvent) => { if (e.pointerType !== 'mouse' || !railRef.current) return drag.current = { x: e.clientX, left: railRef.current.scrollLeft, moved: false, active: true } } const onPointerMove = (e: ReactPointerEvent) => { 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 (

{title}

{blurb &&

{blurb}

}
{featured.length > 1 && (
{[ [-1,
)}
{error ? (

Couldn’t load the timeline. {error}{' '}

) : loading ? (
) } 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 && ( )}

{dateLabel(item)}

{item.title}

{item.meta &&

{item.meta}

} {item.blurb && (

{item.blurb}

)} {href && ( Read more )} ) const card = 'flex flex-1 flex-col rounded-3xl border border-brand/15 bg-surface p-7 shadow-sm' return (
{/* The line, its dot, and the year where it changes. */}
{showYear && ( {year(item)} )}
{href ? ( {body} ) : (
{body}
)}
) }