import React, { useEffect, useRef } from 'react'; import { Box, Typography, Paper, Avatar } from '@mui/material'; import type { DocumentMetadata } from '../../../electron/types'; import ReactMarkdown from 'react-markdown'; import rehypeHighlight from 'rehype-highlight'; import 'highlight.js/styles/github.css'; interface ChatMessage { id: string; text: string; isUser: boolean; timestamp: string; sources?: DocumentMetadata[]; avatar?: string; } interface MessageListProps { messages: ChatMessage[]; } export default function MessageList({ messages }: MessageListProps) { const messageListRef = useRef(null); useEffect(() => { if (messageListRef.current) { messageListRef.current.scrollTop = messageListRef.current.scrollHeight; } }, [messages]); return ( theme.palette.divider, borderRadius: '4px', '&:hover': { background: (theme) => theme.palette.action.hover, }, }, '&::-webkit-scrollbar-track': { background: 'transparent', }, }}> {messages.map((message) => ( {message.isUser ? 'User' : 'Data Hound'} theme.palette.mode === 'dark' ? '#1e1e1e' : '#f6f8fa', padding: 2, borderRadius: 1, overflow: 'auto' }, '& code': { backgroundColor: (theme) => theme.palette.mode === 'dark' ? '#1e1e1e' : '#f6f8fa', padding: '0.2em 0.4em', borderRadius: 1, fontSize: '85%' }, '& h1, & h2, & h3, & h4, & h5, & h6': { marginTop: '24px', marginBottom: '16px', fontWeight: 600, lineHeight: 1.25 }, '& p': { marginTop: '0', marginBottom: '16px' }, '& a': { color: (theme) => theme.palette.primary.main, textDecoration: 'none', '&:hover': { textDecoration: 'underline' } }, '& img': { maxWidth: '100%', height: 'auto' }, '& blockquote': { padding: '0 1em', color: (theme) => theme.palette.text.secondary, borderLeft: (theme) => `0.25em solid ${theme.palette.divider}`, margin: '0 0 16px 0' }, '& ul, & ol': { paddingLeft: '2em', marginBottom: '16px' } } }}> {message.text} {message.sources && message.sources.length > 0 && ( Sources: {message.sources.map((source, index) => ( {source.path} ))} )} {new Date(message.timestamp).toLocaleTimeString()} ))} ); }