diff --git a/frontend/src/lib/timeline/timelineMeta.ts b/frontend/src/lib/timeline/timelineMeta.ts index 7052c405..38b40ea7 100644 --- a/frontend/src/lib/timeline/timelineMeta.ts +++ b/frontend/src/lib/timeline/timelineMeta.ts @@ -21,11 +21,18 @@ export interface TimelineMeta { */ export function timelineMeta(timeline: TimelineDTO): TimelineMeta { const years = timeline.years; - const allEntries = [...years.flatMap((y) => y.entries), ...timeline.undated]; + let letterCount = 0; + let eventCount = 0; + const tally = (e: TimelineDTO['undated'][number]) => { + if (e.kind === 'LETTER') letterCount += 1; + else if (e.kind === 'EVENT') eventCount += 1; + }; + for (const y of years) for (const e of y.entries) tally(e); + for (const e of timeline.undated) tally(e); 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 + letterCount, + eventCount }; }