NGU-Web/src/lib/useFrontPage.ts
Aidan Dona 14a22ca44d Video stills: Frame at on video blocks and the front page's video, and Tools > Video thumbnails (migration 074)
Frame at (a still from a YouTube or Facebook video at a typed time)
now also fills a video block's still and the front page's new Video
still, which the hero shows before its featured video plays. Tools >
Video thumbnails takes one from any link, to download or copy into a
field. All go through the existing POST /api/admin/video-frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 12:10:44 -05:00

138 lines
4.3 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
FRONT PAGE DATA
GET /front-page, as routes/home.js shapes it: the hero, the
visible sections in order, counted stats, paths with actions,
and the countdown's event. Edited in the admin under Front page.
No fallback content. If the request fails the page says so: a
plausible default home page would hide a broken server behind
something that looks fine.
═══════════════════════════════════════════════════════════════ */
import { useRecord, type Resource } from './useRecord.ts'
import type { EventSeries } from './eventSeries.ts'
import type { Link } from './useContent.ts'
/** What fills the hero's background. */
export type HeroBackdrop = 'brand' | 'photos'
/** What sits beside the words, over the backdrop. */
export type HeroFeature = 'none' | 'livestream' | 'video' | 'event'
/** The CHECK list on front_page_sections.section. */
export type FrontPageSectionKey =
| 'countdown'
| 'retreats'
| 'calendar'
| 'stats'
| 'timeline'
| 'connect'
| 'featured'
export type HeroButton = { label: string; url: string }
export type HeroSlide = {
media: string
alt?: string | null
caption?: string | null
link_url?: string | null
}
export type Hero = {
backdrop: HeroBackdrop
feature: HeroFeature
eyebrow?: string | null
headline: string
subhead?: string | null
primary: HeroButton | null
secondary: HeroButton | null
slide_seconds: number
slides: HeroSlide[]
livestream: { url: string; title?: string | null } | null
/** A link to embed or a video file; see videoSource in embeds.ts. */
/** `still` is shown before it plays; resolve it with mediaUrl. */
video: { url: string; title?: string | null; captions?: string | null; still?: string | null } | null
/** With the 'event' feature: the pinned event, else the countdown's. */
event: HeroEvent | null
}
export type FrontPageSection = {
section: FrontPageSectionKey
/** Null → the section's own heading. */
title?: string | null
blurb?: string | null
}
export type FrontPageStat = {
label: string
/** Already counted or typed; never null, since the API drops those. */
value: string
suffix?: string | null
note?: string | null
}
export type PathAction = { label: string; description?: string | null; url: string }
export type FrontPagePath = {
label: string
icon?: string | null
blurb?: string | null
actions: PathAction[]
}
export type CountdownEvent = {
id: string
title: string
theme?: string | null
starts_on?: string | null
ends_on?: string | null
date_label?: string | null
location_label?: string | null
is_online: boolean
color?: string | null
event_logo?: string | null
series: EventSeries | null
}
/** One featured card, as loadFeaturedCards in shape.js shapes it.
* A record card's title and image are already its record's unless
* the card overrides them; `ref` is what its link is built from. */
export type FeaturedCard = {
kind: 'record' | 'link' | 'video'
ref: { kind: string; id: string; org_kind?: string | null } | null
url: string | null
eyebrow?: string | null
title?: string | null
blurb?: string | null
/** Resolve the file with mediaUrl in media.ts. */
image: { file: string; kind: string } | null
/** Its shape in the grid; null is automatic (FeaturedCards). */
size?: FeaturedSize | null
}
export type FeaturedSize = 'normal' | 'wide' | 'tall' | 'large'
export type FeaturedColumns = 2 | 3 | 4
/** The countdown's event plus what the hero's event card draws. */
export type HeroEvent = CountdownEvent & {
tagline?: string | null
photo?: string | null
photo_alt?: string | null
org_logo?: string | null
links: Link[]
}
export type FrontPage = {
hero: Hero
sections: FrontPageSection[]
stats: FrontPageStat[]
paths: FrontPagePath[]
featured: FeaturedCard[]
/** Columns across on a wide screen; null is the grid's default. */
featured_columns: FeaturedColumns | null
countdown: CountdownEvent | null
}
export const useFrontPage = (): Resource<FrontPage> =>
useRecord<FrontPage>('/front-page', 'front_page')