import { useState, useEffect, useRef } from 'react'; import styles from '../styles/index.module.css'; import ReactMarkdown from 'react-markdown'; interface ChatWindowProps { messages: { sender: 'user' | 'bot'; text: string }[]; onSendMessage: (message: string) => void; } export default function ChatWindow({ messages, onSendMessage, }: ChatWindowProps) { const [input, setInput] = useState(''); const messagesEndRef = useRef(null); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSendMessage(input); setInput(''); }; useEffect(() => { if (messagesEndRef.current) { messagesEndRef.current.scrollIntoView({ behavior: 'smooth' }); } }, [messages]); return (
{messages.map((msg, index) => (
{msg.text}
))}
setInput(e.target.value)} placeholder="Type a message..." className={styles.inputField} />
); }