- One mediaUrl in media.ts instead of 12 identical aliases and a kind map; orgPath builds on hrefs.ts's orgHref - One Logo component (hides itself or shows a fallback when the file is missing) for event cards, org lists and chapter marks - useHistory is a thin wrapper over useRecord - adminSchema.ts split into adminSchema/, one file per entity plus shared.ts; the registry is unchanged (checked by loading both) - JS smooth scrolls respect reduced motion (lib/motion.ts) - Content-Security-Policy in Report-Only, with /api/csp-report logging what it would block Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
4.4 KiB
TypeScript
127 lines
4.4 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
|
FEATURED CARDS
|
|
|
|
A grid of cards that point somewhere: the front page's featured
|
|
band now, the Community blog's posts next. The data comes from
|
|
loadFeaturedCards in server/src/shape.js, already resolved, so
|
|
this only draws.
|
|
|
|
Three kinds of card:
|
|
|
|
record links to the record's own page (hrefs.ts builds it)
|
|
link links to its URL, a new tab when it leaves the site
|
|
video VideoPlayer: a still with a play button that swaps in
|
|
the player when pressed. The still is the card's
|
|
image, else YouTube's thumbnail, else a plain panel.
|
|
|
|
A photo fills the picture area; a logo sits inside it on a soft
|
|
panel instead, since cropping a logo to 16:9 cuts it off.
|
|
═══════════════════════════════════════════════════════════════ */
|
|
|
|
import { useState } from 'react'
|
|
|
|
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
|
import VideoPlayer from './VideoPlayer.tsx'
|
|
import { refHref } from '../lib/hrefs.ts'
|
|
import { mediaUrl } from '../lib/media.ts'
|
|
import type { FeaturedCard } from '../lib/useFrontPage.ts'
|
|
|
|
/* Image kinds that are photographs, drawn edge to edge. Anything
|
|
else is a logo, drawn whole. */
|
|
const PHOTO_KINDS = new Set(['event-background', 'featured', 'person'])
|
|
|
|
function hrefFor(card: FeaturedCard): string | null {
|
|
if (card.kind === 'record' && card.ref) {
|
|
return refHref(card.ref.kind, card.ref.id, card.ref.org_kind)
|
|
}
|
|
return card.kind === 'link' ? card.url : null
|
|
}
|
|
|
|
function Picture({ card }: { card: FeaturedCard }) {
|
|
const [failed, setFailed] = useState(false)
|
|
const src = card.image ? mediaUrl(card.image.file) : null
|
|
const photo = card.image ? PHOTO_KINDS.has(card.image.kind) : false
|
|
|
|
if (!src || failed) {
|
|
return <div className="aspect-video w-full bg-tint" />
|
|
}
|
|
|
|
return photo ? (
|
|
<img
|
|
src={src}
|
|
alt=""
|
|
loading="lazy"
|
|
onError={() => setFailed(true)}
|
|
className="aspect-video w-full object-cover"
|
|
/>
|
|
) : (
|
|
<div className="flex aspect-video w-full items-center justify-center bg-tint p-8">
|
|
<img
|
|
src={src}
|
|
alt=""
|
|
loading="lazy"
|
|
onError={() => setFailed(true)}
|
|
className="max-h-full max-w-full object-contain"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function VideoPicture({ card }: { card: FeaturedCard }) {
|
|
const own = card.image ? mediaUrl(card.image.file) : null
|
|
return <VideoPlayer url={card.url} still={own} title={card.title} />
|
|
}
|
|
|
|
function Card({ card }: { card: FeaturedCard }) {
|
|
const href = hrefFor(card)
|
|
|
|
const text = (
|
|
<div className="flex flex-1 flex-col p-6">
|
|
{card.eyebrow && (
|
|
<p className="text-xs font-bold uppercase tracking-[0.2em] text-link">{card.eyebrow}</p>
|
|
)}
|
|
{card.title && (
|
|
<h3 className="mt-2 font-display text-xl font-extrabold leading-snug text-ink">
|
|
{href ? (
|
|
// Stretched over the whole card, so the picture and the
|
|
// blurb are part of the click without nesting links.
|
|
<HomeLink
|
|
url={href}
|
|
className="after:absolute after:inset-0 after:rounded-2xl after:content-[''] hover:underline"
|
|
>
|
|
{card.title}
|
|
</HomeLink>
|
|
) : (
|
|
card.title
|
|
)}
|
|
</h3>
|
|
)}
|
|
{card.blurb && <p className="mt-2 leading-relaxed text-muted">{card.blurb}</p>}
|
|
</div>
|
|
)
|
|
|
|
return (
|
|
<li className="relative flex flex-col overflow-hidden rounded-2xl border border-brand/15 bg-surface shadow-sm transition-shadow hover:shadow-lg">
|
|
{card.kind === 'video' ? (
|
|
// Above the stretched link, which a video card doesn't have
|
|
// anyway, so the play button always gets the click.
|
|
<div className="relative z-10">
|
|
<VideoPicture card={card} />
|
|
</div>
|
|
) : (
|
|
<Picture card={card} />
|
|
)}
|
|
{text}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
export default function FeaturedCards({ cards }: { cards: FeaturedCard[] }) {
|
|
return (
|
|
<ul className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
|
{cards.map((card, index) => (
|
|
<Card key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`} card={card} />
|
|
))}
|
|
</ul>
|
|
)
|
|
}
|