NGU-Web/src/pages/PersonDetail.tsx
Zaldimmar 222c9e69a2 Third audit, UI half; side nav on top; request button colors
- Event cards: lazy -640 photo, only nearby slides drawn, a counter
  past 12 events, past grid paged with Show more
- Community map: search over list and grid, 12 per region then Show
  all, list no longer redrawn on hover
- People tiles: one clip check for the list, Show all past 30
- Person pages: 6 events and posts then Show all; excerpts load only
  the first paragraph
- Admin: filter box on long pickers and the QR select, options sent
  per form, Media thumbnails from the small copy, debounced searches
  that drop stale answers
- Pages show their last data while refreshing after the cache TTL
- Side nav stacks above page content (the carousel arrows)
- No event request button on National Retreats; request buttons take
  their section's accent
- Version v1.11.1-audit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 19:09:21 -05:00

419 lines
13 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ═══════════════════════════════════════════════════════════════
PERSON DETAIL: /people/:id
Everything public that points at one person, gathered by
GET /people/:id in people.js. Visibility is decided there, the
same way each list's own page decides it, so nothing here
filters.
Roles are current and past. A roster only ever wants who holds
a seat now; a person's record is also where "served on the board
2018–2022" belongs, so ended affiliations list under Previously.
public_phone is never sent. The email is the one contact detail
the page offers.
Sections after About alternate background in the order they
appear, so a person with no roles doesn't get two tinted bands
in a row.
═══════════════════════════════════════════════════════════════ */
import { useState, type ReactNode } from 'react'
import { Link, useParams } from 'react-router-dom'
import PageShell, { type ShellSection } from '../components/PageShell.tsx'
import PageState from '../components/PageState.tsx'
import PlatformIcon from '../components/PlatformIcon.tsx'
import ContentBlocks from '../components/ContentBlocks.tsx'
import { PostCard } from './sections/CommunityBlog.tsx'
import {
usePerson,
type PersonEvent,
type PersonRecord,
type PersonRole,
} from '../lib/useContent.ts'
import { awardHref, eventHref, orgHref, teamHref } from '../lib/hrefs.ts'
import { mediaUrl, initials } from '../lib/media.ts'
import { eventTypeLabel } from '../lib/eventTypes.ts'
import { capitalize } from '../lib/text.ts'
import { accentText, BRAND } from '../lib/color.ts'
const BODY = 'var(--color-muted)'
/* Events and posts show this many, then "Show all". */
const SHOW_FIRST = 6
/* affiliations.role, for a row with no title of its own. */
const ROLE_LABEL: Record<string, string> = {
lead: 'Lead',
board: 'Board member',
staff: 'Staff',
volunteer: 'Volunteer',
member: 'Member',
}
export default function PersonDetail() {
const { id } = useParams()
const { data: person, loading, error, notFound, reload } = usePerson(id)
if (!person) {
return (
<PageState
loading={loading}
error={error}
notFound={notFound}
onRetry={reload}
noun="person"
backTo="/organization"
backLabel="Organization"
/>
)
}
const accent = BRAND
const current = person.roles.filter((role) => !role.ended_on)
const previous = person.roles.filter((role) => role.ended_on)
const sections: ShellSection[] = [
{
id: 'about',
title: 'About',
accent,
content: (
<div className="max-w-6xl mx-auto px-6 space-y-8">
<Facts person={person} accent={accent} />
{[...person.bio, ...person.description].map((paragraph, index) => (
<p key={index} className="leading-relaxed max-w-3xl" style={{ color: BODY }}>
{paragraph}
</p>
))}
<div className="max-w-3xl">
<ContentBlocks blocks={person.blocks} accent={accent} />
</div>
<Contact person={person} accent={accent} />
</div>
),
},
]
if (person.roles.length > 0) {
sections.push({
id: 'roles',
title: 'Roles',
accent,
content: (
<div className="max-w-6xl mx-auto px-6 space-y-8">
{current.length > 0 && <RoleList roles={current} accent={accent} />}
{previous.length > 0 && (
<div>
{current.length > 0 && (
<h3 className="mb-4 text-lg font-bold" style={{ color: accentText(accent) }}>
Previously
</h3>
)}
<RoleList roles={previous} accent={accent} />
</div>
)}
</div>
),
})
}
if (person.events.length > 0) {
sections.push({
id: 'events',
title: 'Events',
accent,
content: (
<div className="max-w-6xl mx-auto px-6">
<Capped items={person.events} accent={accent}>
{(events) => (
<ul className="space-y-5">
{events.map((event) => (
<li key={event.id}>
<EventRow event={event} accent={accent} />
</li>
))}
</ul>
)}
</Capped>
</div>
),
})
}
if (person.awards.length > 0) {
sections.push({
id: 'awards',
title: 'Awards',
accent,
content: (
<div className="max-w-6xl mx-auto px-6 space-y-6">
{person.awards.map((entry, index) => (
<div
key={`${entry.award.id}:${entry.awarded_on ?? index}`}
className="border-l-2 pl-5"
style={{ borderColor: accent }}
>
<p className="font-semibold" style={{ color: accentText(accent) }}>
<Link to={awardHref(entry.award.id)} className="hover:underline">
{entry.award.name}
</Link>
</p>
{(entry.awarded_on || entry.event) && (
<p className="text-sm" style={{ color: BODY }}>
{year(entry.awarded_on)}
{entry.event && (
<>
{entry.awarded_on && ' · '}
<Link
to={eventHref(entry.event.id)}
className="hover:underline"
style={{ color: accentText(accent) }}
>
{entry.event.title}
</Link>
</>
)}
</p>
)}
{entry.citation && (
<p className="mt-1 max-w-2xl italic leading-relaxed" style={{ color: BODY }}>
{entry.citation}
</p>
)}
</div>
))}
</div>
),
})
}
if (person.posts?.length > 0) {
sections.push({
id: 'posts',
title: 'Blog posts',
accent,
content: (
<div className="max-w-6xl mx-auto px-6">
<Capped items={person.posts} accent={accent}>
{(posts) => (
<ul className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{posts.map((post) => (
<PostCard key={post.id} post={post} accent={accent} />
))}
</ul>
)}
</Capped>
</div>
),
})
}
return (
<PageShell title={person.name} intro={person.tagline ?? undefined} sections={sections} />
)
}
/* The first SHOW_FIRST of a list, then a button for the rest. */
function Capped<T>({
items,
accent,
children,
}: {
items: T[]
accent: string
children: (shown: T[]) => ReactNode
}) {
const [all, setAll] = useState(false)
const more = !all && items.length > SHOW_FIRST
return (
<>
{children(more ? items.slice(0, SHOW_FIRST) : items)}
{more && (
<button
type="button"
onClick={() => setAll(true)}
className="btn mt-6 px-5 py-2 text-sm"
style={{ border: `1px solid ${accent}`, color: accentText(accent) }}
>
Show all {items.length}
</button>
)}
</>
)
}
/* ── The strip of facts under the heading ────────────────────── */
function Facts({ person, accent }: { person: PersonRecord; accent: string }) {
const photo = mediaUrl(person.photo)
return (
<div className="flex flex-wrap items-center gap-x-6 gap-y-3 text-sm">
{photo ? (
<img
src={photo}
alt=""
loading="lazy"
decoding="async"
className="h-24 w-24 shrink-0 object-cover"
/>
) : (
<span
aria-hidden="true"
className="flex h-24 w-24 shrink-0 items-center justify-center text-2xl font-bold text-white"
style={{ background: accent }}
>
{initials(person.name)}
</span>
)}
{person.pronouns && <span style={{ color: BODY }}>{person.pronouns}</span>}
{person.org && (
<Link
to={orgHref(person.org.id, person.org.kind)}
className="font-medium hover:underline"
style={{ color: accentText(accent) }}
>
{person.org.name}
</Link>
)}
{person.location_label && <span style={{ color: BODY }}>{person.location_label}</span>}
<Link to="/organization#leadership" className="ml-auto hover:underline" style={{ color: accentText(accent) }}>
Leadership
</Link>
</div>
)
}
function Contact({ person, accent }: { person: PersonRecord; accent: string }) {
const outlined = [
person.website ? { url: person.website, label: 'Website', platform: null } : null,
person.public_email
? { url: `mailto:${person.public_email}`, label: person.public_email, platform: null }
: null,
...person.socials,
].filter((link): link is NonNullable<typeof link> => Boolean(link))
if (person.links.length === 0 && outlined.length === 0) return null
return (
<div className="flex flex-wrap gap-3">
{person.links.map((link) => (
<a
key={link.url}
href={link.url}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-2 btn px-5 py-2 text-sm text-white transition-transform hover:scale-105"
style={{ background: accent }}
>
<PlatformIcon platform={link.platform} />
{link.label}
</a>
))}
{outlined.map((link) => (
<a
key={link.url}
href={link.url}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-2 btn border px-4 py-1.5 text-sm transition-colors hover:bg-tint"
style={{ borderColor: accent, color: accentText(accent) }}
>
<PlatformIcon platform={link.platform} />
{link.label}
</a>
))}
</div>
)
}
/* ── Roles ───────────────────────────────────────────────────── */
function RoleList({ roles, accent }: { roles: PersonRole[]; accent: string }) {
return (
<ul className="grid gap-4 sm:grid-cols-2">
{roles.map((role, index) => (
<li
key={`${role.org.id}:${role.team?.id ?? ''}:${role.title ?? role.role}:${index}`}
className="border-l-4 bg-surface px-5 py-3"
style={{ borderColor: accent }}
>
<p className="font-semibold" style={{ color: accentText(accent) }}>
{role.title || ROLE_LABEL[role.role] || capitalize(role.role)}
</p>
<p className="text-sm" style={{ color: BODY }}>
{role.team && (
<>
<Link to={teamHref(role.team.id)} className="hover:underline">
{role.team.name}
</Link>
{' · '}
</>
)}
<Link to={orgHref(role.org.id, role.org.kind)} className="hover:underline">
{role.org.name}
</Link>
</p>
{tenure(role) && (
<p className="text-xs" style={{ color: BODY }}>
{tenure(role)}
</p>
)}
</li>
))}
</ul>
)
}
/* "2018 – 2022", "Since 2021", "Until 2019", or null. Years only:
affiliation dates are often backfilled from memory. */
function tenure(role: PersonRole): string | null {
const from = year(role.started_on)
const to = year(role.ended_on)
if (from && to) return from === to ? from : `${from} – ${to}`
if (from) return `Since ${from}`
if (to) return `Until ${to}`
return null
}
/* ── Events ──────────────────────────────────────────────────── */
function EventRow({ event, accent }: { event: PersonEvent; accent: string }) {
const when = event.date_label || year(event.starts_on)
const capacities = event.roles
.map((role) => role.title || capitalize(role.role))
.join(', ')
return (
<div className="border-l-2 pl-5" style={{ borderColor: accent }}>
<p className="font-semibold" style={{ color: accentText(accent) }}>
<Link to={eventHref(event.id)} className="hover:underline">
{event.title}
</Link>
</p>
<p className="text-sm" style={{ color: BODY }}>
{[capacities, eventTypeLabel(event.event_type), when].filter(Boolean).join(' · ')}
</p>
</div>
)
}
/* Dates here may be partial ('2019', '2019-06'), so take the
leading year rather than parsing. */
function year(date?: string | null): string | null {
if (!date) return null
const match = /^(\d{4})/.exec(date)
return match ? match[1] : date
}