import { Link } from 'react-router-dom' import type { JournalEntry } from '../../types/journal' import type { BossResult, BossBattle } from '../../types/game' interface JournalListProps { entries: JournalEntry[] runId: number bossResults?: BossResult[] bosses?: BossBattle[] onNewEntry?: () => void } function formatDate(dateString: string): string { return new Date(dateString).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric', }) } function getPreviewSnippet(body: string, maxLength = 120): string { const stripped = body.replace(/[#*_`~[\]]/g, '').replace(/\n+/g, ' ').trim() if (stripped.length <= maxLength) return stripped return stripped.slice(0, maxLength).trim() + '...' } export function JournalList({ entries, runId, bossResults = [], bosses = [], onNewEntry, }: JournalListProps) { const bossResultMap = new Map(bossResults.map((br) => [br.id, br])) const bossMap = new Map(bosses.map((b) => [b.id, b])) const getBossName = (bossResultId: number | null): string | null => { if (bossResultId == null) return null const result = bossResultMap.get(bossResultId) if (!result) return null const boss = bossMap.get(result.bossBattleId) return boss?.name ?? null } if (entries.length === 0) { return (

No journal entries yet.

{onNewEntry && ( )}
) } return (
{onNewEntry && (
)} {entries.map((entry) => { const bossName = getBossName(entry.bossResultId) return (

{entry.title}

{getPreviewSnippet(entry.body)}

{bossName && ( {bossName} )}
) })}
) }