NGU-Web/src/pages/AwardDetail.tsx
Zaldimmar 2ad65cdc15 Write the site in US English
color, center, canceled, labeled, recognize and the rest, in UI
text, help text, comments, docs and names (ColorInput, QrCenter).
Migration 053 renames the two Site settings color CHECKs, whose
names are the messages the admin shows. Kept: events.status's
stored value 'cancelled' (shown as canceled), aria-labelledby,
schema.org's EventCancelled, and old migrations as they ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 13:24:11 -05:00

178 lines
5.7 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 { mediaUrl, initials } from '../lib/media.ts'
import { accentText, BRAND } from '../lib/color.ts'
const BODY = 'var(--color-muted)'
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 = BRAND
const logo = mediaUrl(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: 'var(--color-surface)',
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="logo-plate 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: accentText(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 = mediaUrl(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: accentText(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: accentText(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 program booklet. */
function year(date?: string | null): string | null {
if (!date) return null
const match = /^(\d{4})/.exec(date)
return match ? match[1] : date
}