178 lines
5.6 KiB
TypeScript
178 lines
5.6 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
|
AWARD DETAIL — /awards/:id
|
|
|
|
The thinnest of the four, by design. `awards` has no links and no
|
|
content blocks — 'award' isn't in the owner_kind CHECK on either
|
|
polymorphic table, and widening it means rebuilding two STRICT
|
|
tables. `description` is the prose.
|
|
|
|
So the recipients are the page. They're rendered as a list rather
|
|
than as PeopleTiles because each one carries a citation, and a
|
|
citation is the point of an award — it doesn't belong folded
|
|
behind a chevron.
|
|
|
|
Note also that `awards` has no is_published column: every row
|
|
here is live the moment it's created. Worth an ADD COLUMN before
|
|
this ships.
|
|
═══════════════════════════════════════════════════════════════ */
|
|
|
|
import { Link, useParams } from 'react-router-dom'
|
|
|
|
import PageShell from '../components/PageShell.tsx'
|
|
import PageState from '../components/PageState.tsx'
|
|
import { useAward, type Recipient } from '../lib/useContent.ts'
|
|
import { eventHref, orgHref, personHref } from '../lib/hrefs.ts'
|
|
import { awardLogo, initials, personPhoto } from '../lib/media.ts'
|
|
|
|
const TEAL = '#138ba0'
|
|
const BODY = '#4a6b72'
|
|
|
|
export default function AwardDetail() {
|
|
const { id } = useParams()
|
|
const { data: award, loading, error, notFound, reload } = useAward(id)
|
|
|
|
if (!award) {
|
|
return (
|
|
<PageState
|
|
loading={loading}
|
|
error={error}
|
|
notFound={notFound}
|
|
onRetry={reload}
|
|
noun="award"
|
|
backTo="/community"
|
|
backLabel="Community"
|
|
/>
|
|
)
|
|
}
|
|
|
|
const accent = TEAL
|
|
const logo = awardLogo(award.logo)
|
|
|
|
return (
|
|
<PageShell
|
|
title={award.name}
|
|
intro={award.description ?? undefined}
|
|
sections={[
|
|
{
|
|
id: 'recipients',
|
|
title: 'Recipients',
|
|
blurb:
|
|
award.recipients.length === 0
|
|
? 'Nobody has received this yet.'
|
|
: undefined,
|
|
accent,
|
|
background: '#ffffff',
|
|
content: (
|
|
<div className="max-w-6xl mx-auto px-6 space-y-8">
|
|
<div className="flex flex-wrap items-center gap-x-6 gap-y-3 text-sm">
|
|
{logo && (
|
|
<img src={logo} alt="" loading="lazy" className="h-12 w-12 object-contain" />
|
|
)}
|
|
|
|
{award.org && (
|
|
<span style={{ color: BODY }}>
|
|
Given by{' '}
|
|
<Link
|
|
to={orgHref(award.org.id, award.org.kind)}
|
|
className="font-medium hover:underline"
|
|
style={{ color: accent }}
|
|
>
|
|
{award.org.name}
|
|
</Link>
|
|
</span>
|
|
)}
|
|
|
|
<span style={{ color: BODY }}>
|
|
{award.recipients.length}{' '}
|
|
{award.recipients.length === 1 ? 'recipient' : 'recipients'}
|
|
</span>
|
|
</div>
|
|
|
|
<ol className="space-y-8">
|
|
{award.recipients.map((recipient, index) => (
|
|
<li key={`${recipient.id}:${recipient.awarded_on ?? index}`}>
|
|
<RecipientRow recipient={recipient} accent={accent} />
|
|
</li>
|
|
))}
|
|
</ol>
|
|
</div>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function RecipientRow({ recipient, accent }: { recipient: Recipient; accent: string }) {
|
|
const photo = personPhoto(recipient.photo)
|
|
|
|
return (
|
|
<div className="flex gap-5">
|
|
{photo ? (
|
|
<img
|
|
src={photo}
|
|
alt=""
|
|
loading="lazy"
|
|
decoding="async"
|
|
className="h-16 w-16 shrink-0 rounded-full object-cover"
|
|
/>
|
|
) : (
|
|
<span
|
|
aria-hidden="true"
|
|
className="flex h-16 w-16 shrink-0 items-center justify-center rounded-full text-sm font-bold text-white"
|
|
style={{ background: accent }}
|
|
>
|
|
{initials(recipient.name)}
|
|
</span>
|
|
)}
|
|
|
|
<div className="min-w-0">
|
|
<p className="text-lg font-semibold">
|
|
<Link
|
|
to={personHref(recipient.id)}
|
|
className="hover:underline"
|
|
style={{ color: accent }}
|
|
>
|
|
{recipient.name}
|
|
</Link>
|
|
</p>
|
|
|
|
<p className="text-sm" style={{ color: BODY }}>
|
|
{[
|
|
year(recipient.awarded_on),
|
|
recipient.tagline,
|
|
]
|
|
.filter(Boolean)
|
|
.join(' · ')}
|
|
{recipient.event && (
|
|
<>
|
|
{(recipient.awarded_on || recipient.tagline) && ' · '}
|
|
<Link
|
|
to={eventHref(recipient.event.id)}
|
|
className="hover:underline"
|
|
style={{ color: accent }}
|
|
>
|
|
{recipient.event.title}
|
|
</Link>
|
|
</>
|
|
)}
|
|
</p>
|
|
|
|
{recipient.citation && (
|
|
<p className="mt-2 max-w-2xl leading-relaxed" style={{ color: BODY }}>
|
|
{recipient.citation}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/* awarded_on may be a partial date, so this takes the leading year
|
|
rather than parsing. A full date would be false precision on a
|
|
row backfilled from a programme booklet. */
|
|
function year(date?: string | null): string | null {
|
|
if (!date) return null
|
|
const match = /^(\d{4})/.exec(date)
|
|
return match ? match[1] : date
|
|
}
|