NGU-Web/src/lib/useContent.ts
Zaldimmar f46deac3cc Image block: a dark theme picture; presented pictures centered
- media_dark (102): shown in place of the image while the site is
  dark, the block's alt text and caption shared
- Present: pictures beside text centered on the slide's height, and a
  section of only pictures centered both ways

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 06:40:40 -06:00

547 lines
17 KiB
TypeScript

/**
* The detail endpoints, typed.
*
* Adding one is a type and a one-line hook, useRecord owns
* the fetching, the caching and the 404.
*
* An id that is missing, or the literal string "undefined", which
* is what a template literal makes of a missing route param, never
* reaches the network. detailPath returns null and the hook reports
* notFound, which is what the visitor should see anyway, and
* hrefs.ts has already logged the component that produced it.
*/
import type { BlogPostSummary } from './useBlog.ts'
import type { FeaturedCard } from './sectionTypes.ts'
import { detailPath } from './hrefs.ts'
import { useRecord, type Resource } from './useRecord.ts'
import type { EventType } from './eventTypes.ts'
import type { EventSeries } from './eventSeries.ts'
/* ── Shared shapes ───────────────────────────────────────────── */
/** A content_blocks row with its `items` child, as shape.js sends it. */
export type ContentBlock = {
id?: number | string
slot?: 'card' | 'body'
/** Its rotating words' own motion (084), else the site's. */
words?: { motion?: any; direction?: any; seconds?: number | null } | null
type:
| 'heading'
| 'subheading'
| 'paragraph'
| 'list'
| 'links'
| 'quote'
| 'image'
| 'divider'
| 'video'
| 'button'
| 'callout'
| 'schedule'
| 'table'
| 'tab'
| 'cards'
| 'people'
| 'map'
| 'events'
| 'organizations'
text?: string | null
media?: string | null
href?: string | null
/** An image's alt text. */
alt?: string | null
/** A people block's team, shown as its members' tiles. */
team_id?: string | null
/** Who a quote is by. */
cite?: string | null
/** A list block's style (092): null bold text, 'plain' the old look. */
list_style?: 'plain' | null
/** An image block's picture for the dark theme (102). */
media_dark?: string | null
/** An image block's size (101): null the column's width. */
image_size?: 'small' | 'medium' | 'large' | null
/** An organizations block's kind, listed when none are picked (093). */
org_kind?: 'region' | 'group' | 'partner' | 'ministry' | null
/** A video block's WebVTT file, for an uploaded video (066). */
captions?: string | null
items?: ContentBlockItem[]
/** A schedule's own tags (087). */
tags?: ScheduleTag[]
/** A map or schedule block's venue (088). */
venue_id?: string | null
venue?: Venue | null
/** A map block's own sections of its venue's locations, by key
* (094). With any, `venue` holds only the locations they name. */
map_sections?: MapSection[]
/** How it's presented (095); null with nothing set. */
present?: BlockPresent | null
}
/** A block's presentation settings (095), EventPresent.tsx. */
export type BlockPresent = {
/** A people block: each one's role or title under their name, as
* the Present setup picks (not stored). */
titles?: boolean
/** Only on the page: left out of the presentation (099). */
hide: boolean
/** Only in the presentation: left off the page (099). */
only: boolean
/** In place of its text, eg. a shorter heading. */
text: string | null
/** A map: a slide per map section. */
map_split: boolean
map_no_list: boolean
map_no_details: boolean
/** A map: which locations get a slide; null every marked one. */
places: 'picked' | 'none' | null
place_keys: string[]
}
/** An event's presentation look (095). */
export type EventPresentLook = {
background: string | null
background_color: string | null
/** Percent of the color over the image; null 60. */
dim: number | null
/** null the accent bar, title line and timer. */
frame: 'border' | 'none' | null
accent: string | null
text_color: string | null
logo: string | null
/** Room clear at each edge (097): percent of the screen's height
* (top, bottom) and width (left, right); null none. */
inset?: { top: number; right: number; bottom: number; left: number } | null
/** In the dark theme (096); a null one takes the above. */
dark?: Partial<Omit<EventPresentLook, 'frame' | 'dark' | 'inset'>>
}
export type MapSection = { name: string; keys: string[] }
/** A venue (088): its map picture and the locations marked on it,
* each a pin (x, y) or a box (x, y, w, h), in percent. */
export type Venue = {
id: string
name: string
address?: string | null
map_image?: string | null
map_alt?: string | null
locations: VenueLocation[]
}
export type VenueLocation = {
key: string
name: string
detail?: string | null
x?: number | null
y?: number | null
w?: number | null
h?: number | null
/** The place in Google and Apple Maps (091). */
google_maps_url?: string | null
apple_maps_url?: string | null
}
/** An event an item names (088): an events block's card, or the
* workshop a schedule entry is. */
export type ItemEvent = {
id: string
title: string
event_type?: string | null
starts_on?: string | null
ends_on?: string | null
date_label?: string | null
color?: string | null
image?: string | null
/** Its own 16:9 photo, and where it is, for showing it in full. */
photo?: string | null
photo_alt?: string | null
location_label?: string | null
blurb?: string | null
/** Its own page's blocks: an events block's events only. */
blocks?: ContentBlock[]
}
/** A schedule's tag (087). `tab` is whether it gets a tab of its own. */
export type ScheduleTag = { key: string; name: string; color?: string | null; tab: boolean }
/** A list, link-row or schedule entry. The schedule fields are
* empty on the other two (034_schedule_block.sql). */
export type ContentBlockItem = {
text: string
detail?: string | null
url?: string | null
day?: string | null
time?: string | null
location?: string | null
description?: string | null
media?: string | null
/** The graphic's alt text; blank means decorative. */
media_alt?: string | null
map?: string | null
/** The entry's own map picture (069), shown in place of Google's. */
map_image?: string | null
person?: { id: string; name: string; photo?: string | null; tagline?: string | null } | null
/** A schedule entry's kind (086); sub-items have none. */
kind?: 'entry' | 'block' | 'break' | 'heading'
/** Picked times, HH:MM; `time` is already what to show. */
start_time?: string | null
end_time?: string | null
featured?: boolean
/** A featured event's heading and subheading (090). */
heading?: string | null
subheading?: string | null
/** An organizations block's organization (093). */
org_id?: string | null
/** A block entry's sub-items. */
items?: ContentBlockItem[]
/** Its block's tags it has, by key (087). */
tags?: string[]
/** The event it is, and its place on the block's venue (088). */
event_id?: string | null
event?: ItemEvent | null
location_key?: string | null
place?: { venue_id: string; key: string; name: string } | null
}
export type Link = {
kind?: string
platform?: string | null
label: string
url: string
is_primary?: boolean
}
export type OrgRef = { id: string; name: string; kind?: string | null }
/* One host of an event. `kind` says which table the id is in;
`org_kind` is the region/group/partner split that decides an
organization's route, and is null for a person. The triple is
exactly what refHref() in hrefs.ts takes. */
export type EventHost = {
kind: 'organization' | 'person'
id: string
name: string
org_kind?: string | null
/** An organization host's team, shown in its place (054). */
team?: { id: string; name: string } | null
}
/* ── Events ──────────────────────────────────────────────────── */
export type EventPerson = {
person_id: string
display_name: string
pronouns?: string | null
tagline?: string | null
photo?: string | null
role?: string | null
title?: string | null
}
export type EventAward = {
award: { id: string; name: string; logo?: string | null }
person: { id: string; name: string; photo?: string | null }
awarded_on?: string | null
citation?: string | null
}
/** A descriptor tag (070_tags.sql), eg. Online or In-Person. */
export type Tag = { id: string; name: string }
export type EventRecord = {
id: string
/** Whose gathering it is: an event_scopes id. */
scope_id: string
/** What kind of gathering it is. Orthogonal to scope_id. */
event_type: EventType
title: string
theme?: string | null
tagline?: string | null
starts_on?: string | null
ends_on?: string | null
date_label?: string | null
status: 'upcoming' | 'past' | 'cancelled'
/** The repeating schedule, or null for a one-off. */
series: EventSeries | null
location_label?: string | null
locality?: string | null
state_code?: string | null
country?: string | null
/** The event carries the "online" tag (v_events). */
is_online: boolean
/** Its tags: on the event's own page only. */
tags?: Tag[]
org_logo?: string | null
event_logo?: string | null
color?: string | null
/** Behind the card only, cropped. See 029_event_card_image.sql. */
card_image?: string | null
/** The event's own 16:9 photo, shown whole. See 061_event_photo.sql. */
photo?: string | null
photo_alt?: string | null
/* In billing order. The first is the one `color` and `org_logo`
fell back to when the event set neither. */
hosts: EventHost[]
description: string[]
links: Link[]
/** The instagram link's label, the handle. See splitLinks in shape.js. */
instagram?: string | null
/** Its headings listed beside the blocks (089). */
show_contents?: boolean
/** Above the link buttons; null shows none (089). */
links_heading?: string | null
/** Its page presented (095). */
present?: EventPresentLook
blocks: ContentBlock[]
people: EventPerson[]
awards: EventAward[]
}
/** One row of GET /events: shapeEvent without the detail-only
* blocks, people and awards. */
export type EventListItem = Omit<EventRecord, 'blocks' | 'people' | 'awards'>
/** An event_scopes row, as GET /events sends it beside the list. */
export type EventScope = { id: string; name: string; sort_order: number }
export const useEvent = (id?: string): Resource<EventRecord> =>
useRecord<EventRecord>(detailPath('/events', id), 'event')
/* ── Organizations ───────────────────────────────────────────── */
export type Leader = {
person_id: string
display_name: string
pronouns?: string | null
title?: string | null
role?: string | null
is_owner: boolean
photo?: string | null
public_email?: string | null
team_id?: string | null
team_name?: string | null
}
export type OrgTeam = {
id: string
name: string
tagline?: string | null
color?: string | null
logo?: string | null
}
export type OrgAward = {
id: string
name: string
description?: string | null
logo?: string | null
recipient_count: number
}
export type OrgEvent = {
id: string
title: string
event_type: EventType
date_label?: string | null
status: string
location_label?: string | null
event_logo?: string | null
color?: string | null
}
/** regions.scope's CHECK values. */
export type RegionScope = 'domestic' | 'international' | 'virtual'
/** A region_areas row as attachRegionDetails sends it. */
export type RegionArea = {
area_code: string
share: number
edge: 'top' | 'bottom' | null
note: string | null
}
export type OrganizationRecord = {
id: string
kind: 'national' | 'region' | 'group' | 'partner'
name: string
short_name?: string | null
tagline?: string | null
color?: string | null
logo?: string | null
venue?: string | null
address?: string | null
locality?: string | null
state_code?: string | null
country?: string | null
location_label?: string | null
tags: Tag[]
description: string[]
blocks: ContentBlock[]
links: Link[]
socials: Link[]
/** Every website and email row (an email's url is the bare address). */
websites: Link[]
emails: Link[]
/* splitLinks in shape.js lifts these out as bare strings, for
cards: the first website's url, the first email's address, the
instagram handle. */
website?: string | null
email?: string | null
instagram?: string | null
/** Shape depends on `kind`; empty object for national and partner. */
details: {
scope?: RegionScope | null
map_note?: string | null
areas?: RegionArea[]
groups?: Array<{ id: string; name: string; location_label?: string | null; logo?: string | null }>
/** A region's own featured cards, in order. */
featured?: FeaturedCard[]
region_id?: string | null
region_name?: string | null
region_color?: string | null
/** A group's Unity ministry: no page of its own, so its website. */
ministry_name?: string | null
ministry_url?: string | null
meets?: string | null
started?: string | null
}
leadership: Leader[]
teams: OrgTeam[]
awards: OrgAward[]
events: OrgEvent[]
}
/** One row of GET /organizations: the card surface and details,
* without the sections only the org's own page loads. */
export type OrganizationListItem = Omit<OrganizationRecord, 'blocks' | 'leadership' | 'teams' | 'awards' | 'events'> & {
sort_order: number
}
export const useOrganization = (id?: string): Resource<OrganizationRecord> =>
useRecord<OrganizationRecord>(detailPath('/organizations', id), 'organization')
/* ── Teams ───────────────────────────────────────────────────── */
/** No members here on purpose, PeopleTiles fetches
* /teams/:id/people itself. See the note in content.js. */
export type TeamRecord = {
id: string
name: string
tagline?: string | null
color?: string | null
logo?: string | null
org: OrgRef
description: string[]
links: Link[]
socials: Link[]
/** The instagram handle. See splitLinks in shape.js. */
instagram?: string | null
blocks: ContentBlock[]
}
export const useTeam = (id?: string): Resource<TeamRecord> =>
useRecord<TeamRecord>(detailPath('/teams', id), 'team')
/* ── Awards ──────────────────────────────────────────────────── */
export type Recipient = {
id: string
name: string
photo?: string | null
tagline?: string | null
awarded_on?: string | null
citation?: string | null
event: { id: string; title: string } | null
}
export type AwardRecord = {
id: string
name: string
description?: string | null
logo?: string | null
org: OrgRef | null
recipients: Recipient[]
}
export const useAward = (id?: string): Resource<AwardRecord> =>
useRecord<AwardRecord>(detailPath('/awards', id), 'award')
/* ── People ──────────────────────────────────────────────────── */
/** One public affiliation. ended_on null means current. */
export type PersonRole = {
title?: string | null
role: 'lead' | 'board' | 'staff' | 'volunteer' | 'member'
is_owner: boolean
started_on?: string | null
ended_on?: string | null
org: OrgRef
/** Null when there's no team, or the team is unpublished. */
team: { id: string; name: string } | null
}
/** A published event this person was billed at or hosted, with
* every capacity they appeared in. 'host' comes from event_hosts. */
export type PersonEvent = {
id: string
title: string
event_type: EventType
date_label?: string | null
starts_on?: string | null
status: 'upcoming' | 'past' | 'cancelled'
roles: { role: string; title?: string | null }[]
}
export type PersonAward = {
award: { id: string; name: string; logo?: string | null }
awarded_on?: string | null
citation?: string | null
event: { id: string; title: string } | null
}
export type PersonRecord = {
id: string
name: string
pronouns?: string | null
tagline?: string | null
photo?: string | null
location_label?: string | null
public_email?: string | null
/** The primary organization, when it's published. */
org: OrgRef | null
/** people.bio split on blank lines. */
bio: string[]
description: string[]
blocks: ContentBlock[]
links: Link[]
socials: Link[]
website?: string | null
instagram?: string | null
/** Current first, then most recently ended. */
roles: PersonRole[]
events: PersonEvent[]
awards: PersonAward[]
/** Blog posts they wrote, newest first. */
posts: BlogPostSummary[]
}
export const usePerson = (id?: string): Resource<PersonRecord> =>
useRecord<PersonRecord>(detailPath('/people', id), 'person')
/* ── Directory ─────────────────────────────────────────────────
GET /directory: every public record that has a page, one list
per kind, each row just enough to build its URL with hrefs.ts. */
export type DirectoryEntry = { id: string; name: string }
export type Directory = {
events: Array<DirectoryEntry & { starts_on?: string | null }>
organizations: Array<DirectoryEntry & { kind: OrganizationRecord['kind'] }>
teams: Array<DirectoryEntry & { org_name: string }>
awards: DirectoryEntry[]
people: DirectoryEntry[]
blog_posts: DirectoryEntry[]
}
export const useDirectory = (): Resource<Directory> =>
useRecord<Directory>('/directory', 'directory')