diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 903f948..6f4f733 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -5,6 +5,7 @@ import { TypingIndicator } from './TypingIndicator'; import type { ChatMessage, ConnectionStatus } from '../types'; import { Bot, ArrowDown } from 'lucide-react'; import { useT } from '../hooks/useLocale'; +import { getLocale, type TranslationKey } from '../lib/i18n'; interface Props { messages: ChatMessage[]; @@ -41,6 +42,24 @@ function hasStreamedText(messages: ChatMessage[]): boolean { return last.blocks.some(b => b.type === 'text' && b.text.trim().length > 0) || (last.content?.trim().length > 0); } +function formatDateSeparator(ts: number, t: (k: TranslationKey) => string): string { + const date = new Date(ts); + const now = new Date(); + const locale = getLocale(); + const bcp47 = locale === 'fr' ? 'fr-FR' : 'en-US'; + + if (date.toDateString() === now.toDateString()) return t('time.today'); + const yesterday = new Date(now); + yesterday.setDate(yesterday.getDate() - 1); + if (date.toDateString() === yesterday.toDateString()) return t('time.yesterday'); + return date.toLocaleDateString(bcp47, { weekday: 'long', day: 'numeric', month: 'long', year: date.getFullYear() !== now.getFullYear() ? 'numeric' : undefined }); +} + +function getDateKey(ts: number): string { + const d = new Date(ts); + return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`; +} + /** Threshold in pixels — if the user is within this distance of the bottom, auto-scroll */ const SCROLL_THRESHOLD = 150; @@ -111,9 +130,26 @@ export function Chat({ messages, isGenerating, status, onSend, onAbort }: Props)