diff --git a/pitch-deck/components/ui/ChatInterface.tsx b/pitch-deck/components/ui/ChatInterface.tsx index 090aee8..fe29cd8 100644 --- a/pitch-deck/components/ui/ChatInterface.tsx +++ b/pitch-deck/components/ui/ChatInterface.tsx @@ -15,6 +15,7 @@ export default function ChatInterface({ lang }: ChatInterfaceProps) { const [messages, setMessages] = useState([]) const [input, setInput] = useState('') const [isStreaming, setIsStreaming] = useState(false) + const [isWaiting, setIsWaiting] = useState(false) const messagesEndRef = useRef(null) const inputRef = useRef(null) @@ -29,6 +30,7 @@ export default function ChatInterface({ lang }: ChatInterfaceProps) { setInput('') setMessages(prev => [...prev, { role: 'user', content: message }]) setIsStreaming(true) + setIsWaiting(true) try { const res = await fetch('/api/chat', { @@ -47,21 +49,28 @@ export default function ChatInterface({ lang }: ChatInterfaceProps) { const decoder = new TextDecoder() let content = '' - setMessages(prev => [...prev, { role: 'assistant', content: '' }]) - while (true) { const { done, value } = await reader.read() if (done) break - content += decoder.decode(value, { stream: true }) - setMessages(prev => { - const updated = [...prev] - updated[updated.length - 1] = { role: 'assistant', content } - return updated - }) + const chunk = decoder.decode(value, { stream: true }) + content += chunk + + if (isWaiting || content.length === chunk.length) { + // First chunk arrived — replace waiting indicator with real content + setIsWaiting(false) + setMessages(prev => [...prev, { role: 'assistant', content }]) + } else { + setMessages(prev => { + const updated = [...prev] + updated[updated.length - 1] = { role: 'assistant', content } + return updated + }) + } } } catch (err) { console.error('Chat error:', err) + setIsWaiting(false) setMessages(prev => [ ...prev, { role: 'assistant', content: lang === 'de' @@ -71,6 +80,7 @@ export default function ChatInterface({ lang }: ChatInterfaceProps) { ]) } finally { setIsStreaming(false) + setIsWaiting(false) } } @@ -135,6 +145,33 @@ export default function ChatInterface({ lang }: ChatInterfaceProps) { ))} + + {/* Waiting indicator — shown between send and first token */} + + {isWaiting && ( + +
+ +
+
+ {[0, 1, 2].map(i => ( + + ))} +
+
+ )} +
+