Finish the audit leftovers

- One mediaUrl in media.ts instead of 12 identical aliases and a
  kind map; orgPath builds on hrefs.ts's orgHref
- One Logo component (hides itself or shows a fallback when the file
  is missing) for event cards, org lists and chapter marks
- useHistory is a thin wrapper over useRecord
- adminSchema.ts split into adminSchema/, one file per entity plus
  shared.ts; the registry is unchanged (checked by loading both)
- JS smooth scrolls respect reduced motion (lib/motion.ts)
- Content-Security-Policy in Report-Only, with /api/csp-report logging
  what it would block

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 22:49:07 -05:00
parent c74ad746f5
commit e4a9c96f7e
42 changed files with 1968 additions and 2043 deletions

View file

@ -1,83 +1,17 @@
/**
* Loads the history timeline from `GET /api/history`.
* Loads the history timeline from `GET /api/history`, through
* useRecord (its `items`), so it shares the cache, the reload that
* invalidates first, and the error handling with every detail page.
*
* Goes through the shared client, so the request is deduped and cached
* for 60s like every other read. Two consequences worth knowing:
*
* · `reload` has to invalidate before it refetches. Without that, the
* retry button inside the TTL would hand back the same settled
* promise and look like it did nothing. A *failed* request is
* already evicted by the client, so this matters for the refresh
* case rather than the error case.
*
* · there's no AbortController. `get` shares one promise between
* callers, so aborting on unmount would cancel someone else's
* request. The `live` flag drops the result instead.
*
*
* `undated` is the number of published entries the API left out because
* nothing gave them a date. Not rendered publicly, a visitor can't act
* on it, but returned so it's reachable if you want a warning in the
* admin later.
* The API also sends `undated`, the number of published entries it
* left out for having no date. Nothing shows it; read it here if the
* admin ever wants a warning.
*/
import { useCallback, useEffect, useState } from 'react'
import { get, invalidate, ApiError } from './api.ts'
import type { TimelineItem } from './timeline.ts'
import { useRecord } from './useRecord.ts'
const PATH = '/history'
type HistoryResponse = {
items?: TimelineItem[]
undated?: number
}
type State = {
items: TimelineItem[]
undated: number
loading: boolean
error: string | null
reload: () => void
}
export function useHistory(): State {
const [items, setItems] = useState<TimelineItem[]>([])
const [undated, setUndated] = useState(0)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
const [attempt, setAttempt] = useState(0)
const reload = useCallback(() => {
invalidate(PATH)
setAttempt((n) => n + 1)
}, [])
useEffect(() => {
let live = true
async function load() {
setLoading(true)
setError(null)
try {
const data: HistoryResponse = await get(PATH)
if (!live) return
setItems(Array.isArray(data?.items) ? data.items : [])
setUndated(Number(data?.undated) || 0)
} catch (err) {
if (!live) return
setError(
err instanceof ApiError ? err.message : "Couldn't reach the server.",
)
} finally {
if (live) setLoading(false)
}
}
load()
return () => {
live = false
}
}, [attempt])
return { items, undated, loading, error, reload }
export function useHistory() {
const { data, loading, error, reload } = useRecord<TimelineItem[]>('/history', 'items')
return { items: data ?? [], loading, error, reload }
}