NGU-Web/src/lib/useFrontPage.ts
Zaldimmar 2e125b4629 Add a reusable event calendar and put it on the front page
EventCalendar shows events on a month grid or as a list of the
month. Multi-day events are lane-packed bars that break at week
edges, series events appear on every meeting with their time, and
clicking a day lists everything on it. Phones get the list. Visitors
can narrow by scope, type, online only and search, all starting at
"all"; a page can pin section, host or type through props, which
hides that control.

Migration 019 rebuilds front_page_sections to allow a 'calendar'
band and slots it in after the retreats carousel, so it can be
reordered, retitled or hidden from the Front page editor.

useEvents drops its empty fallback so a failed request surfaces as
an error rather than an empty list, and returns the scope list
alongside the events for the calendar's scope filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 06:28:42 -05:00

95 lines
2.6 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'
export type HeroMode = 'brand' | 'photos' | 'livestream'
/** The CHECK list on front_page_sections.section. */
export type FrontPageSectionKey =
| 'countdown'
| 'retreats'
| 'calendar'
| 'stats'
| 'timeline'
| 'connect'
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 = {
mode: HeroMode
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
}
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 — 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
}
export type FrontPage = {
hero: Hero
sections: FrontPageSection[]
stats: FrontPageStat[]
paths: FrontPagePath[]
countdown: CountdownEvent | null
}
export const useFrontPage = (): Resource<FrontPage> =>
useRecord<FrontPage>('/front-page', 'front_page')