import React, { useEffect, useRef } from 'react'; import MessageBubble from './MessageBubble'; export default function ChatWindow({ messages, loadingHistory, streaming, onSendMessage, onCancel, activeSession, onTogglePanel }) { const bottomRef = useRef(null); const inputRef = useRef(null); const [input, setInput] = React.useState(''); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); function handleSend() { const text = input.trim(); if (!text || streaming) return; setInput(''); onSendMessage(text); } function handleKeyDown(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } } return (
{/* Header */}
{activeSession ? (activeSession.name || activeSession.external_id) : 'No session selected'}
{/* Message thread */}
{!activeSession && (
✦

Select a session or start a new chat

)} {loadingHistory && (
Loading history...
)} {!loadingHistory && messages.map(msg => ( ))}
{/* Input bar */}