feat(timeline): derive header meta figures from the DTO (REQ-002)

A pure timelineMeta() returns the year range (first/last band, null when
there are no bands) and the letter/event totals across all year bands plus
the undated bucket — the single place these counts are computed.

Refs #833
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-14 10:58:25 +02:00
parent e0b096f12c
commit a1e57ff8cf
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import type { components } from '$lib/generated/api';
type TimelineDTO = components['schemas']['TimelineDTO'];
export interface TimelineMeta {
/** First year band's year, or `null` when there are no bands. */
firstYear: number | null;
/** Last year band's year, or `null` when there are no bands. */
lastYear: number | null;
/** Every `LETTER` entry across all year bands plus the undated bucket. */
letterCount: number;
/** Every `EVENT` entry (derived, curated, and historical) across all bands plus undated. */
eventCount: number;
}
/**
* Derives the header meta-line figures from a loaded `TimelineDTO` (REQ-002):
* the year range (first/last band) and the letter/event totals across every
* year band plus the undated bucket. Pure and the single place these counts
* live — the route renders them; `TimelineView` never recomputes them.
*/
export function timelineMeta(timeline: TimelineDTO): TimelineMeta {
const years = timeline.years;
const allEntries = [...years.flatMap((y) => y.entries), ...timeline.undated];
return {
firstYear: years.length ? years[0].year : null,
lastYear: years.length ? years[years.length - 1].year : null,
letterCount: allEntries.filter((e) => e.kind === 'LETTER').length,
eventCount: allEntries.filter((e) => e.kind === 'EVENT').length
};
}