import { useState, useRef, useEffect } from 'react' import './ChatBox.css' export default function ChatBox({ messages, onSendMessage, loading }) { const [inputValue, setInputValue] = useState('') const messagesEndRef = useRef(null) const inputRef = useRef(null) const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) } useEffect(() => { scrollToBottom() }, [messages]) const handleSend = () => { if (inputValue.trim() && !loading) { onSendMessage(inputValue) setInputValue('') setTimeout(() => inputRef.current?.focus(), 0) } } const handleKeyPress = (e) => { if (e.key === 'Enter' && !e.shiftKey && !loading) { e.preventDefault() handleSend() } } return (
{messages.length === 0 ? (
🤖

Willkommen!

Starte eine Unterhaltung mit dem Zephyr-7B Modell

) : ( messages.map((msg) => (
{msg.role === 'user' ? '👤' : '🤖'}
{msg.content}
{msg.stats && (
⏱️ {msg.stats.time}s • 📊 {msg.stats.tokens} tokens
)}
)) )} {loading && (
🤖
)}