v1.5 - history and timeline as well as many datastructure updates added, polished, fixes
This commit is contained in:
parent
1f0aa3078f
commit
1d84400aef
63 changed files with 7927 additions and 208 deletions
243
src/lib/useContent.ts
Normal file
243
src/lib/useContent.ts
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
/**
|
||||
* The four detail endpoints, typed.
|
||||
*
|
||||
* Adding a fifth 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 { detailPath } from './hrefs.ts'
|
||||
import { useRecord, type Resource } from './useRecord.ts'
|
||||
import type { EventType } from './eventTypes.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'
|
||||
type:
|
||||
| 'heading'
|
||||
| 'subheading'
|
||||
| 'paragraph'
|
||||
| 'list'
|
||||
| 'links'
|
||||
| 'quote'
|
||||
| 'image'
|
||||
| 'divider'
|
||||
text?: string | null
|
||||
media?: string | null
|
||||
href?: string | null
|
||||
items?: Array<{ text: string; detail?: string | null; url?: 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/chapter/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
|
||||
}
|
||||
|
||||
/* ── 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
|
||||
}
|
||||
|
||||
export type EventRecord = {
|
||||
id: string
|
||||
/** Which band of the Retreats page this belongs to. */
|
||||
section_id: string
|
||||
/** What kind of gathering it is. Orthogonal to section_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'
|
||||
location_label?: string | null
|
||||
locality?: string | null
|
||||
state_code?: string | null
|
||||
country?: string | null
|
||||
is_online: boolean
|
||||
org_logo?: string | null
|
||||
event_logo?: string | null
|
||||
color?: string | null
|
||||
gradient?: 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[]
|
||||
instagram?: Link | null
|
||||
blocks: ContentBlock[]
|
||||
people: EventPerson[]
|
||||
awards: EventAward[]
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
export type OrganizationRecord = {
|
||||
id: string
|
||||
kind: 'national' | 'region' | 'chapter' | '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
|
||||
is_online: boolean
|
||||
description: string[]
|
||||
blocks: ContentBlock[]
|
||||
links: Link[]
|
||||
socials: Link[]
|
||||
website?: Link | null
|
||||
email?: Link | null
|
||||
instagram?: Link | null
|
||||
/** Shape depends on `kind`; empty object for national and partner. */
|
||||
details: {
|
||||
scope?: string | null
|
||||
map_note?: string | null
|
||||
areas?: Array<{ area_code: string; share?: number | null; edge?: string | null; note?: string | null }>
|
||||
chapters?: Array<{ id: string; name: string; location_label?: string | null; logo?: string | null }>
|
||||
region_id?: string | null
|
||||
region_name?: string | null
|
||||
region_color?: string | null
|
||||
meets?: string | null
|
||||
started?: string | null
|
||||
}
|
||||
leadership: Leader[]
|
||||
teams: OrgTeam[]
|
||||
awards: OrgAward[]
|
||||
events: OrgEvent[]
|
||||
}
|
||||
|
||||
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[]
|
||||
instagram?: Link | 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')
|
||||
Loading…
Add table
Add a link
Reference in a new issue