Spaces:
Sleeping
Sleeping
File size: 1,152 Bytes
47203d3 5f9e2bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import { useEffect, useRef } from 'react'
import type { Message } from '../../types'
import MessageBubble from './MessageBubble'
interface Props {
messages: Message[]
loading: boolean
}
export default function ChatWindow({ messages, loading }: Props) {
const bottomRef = useRef<HTMLDivElement>(null)
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' })
}, [messages, loading])
return (
<div className="flex-1 overflow-y-auto px-4 py-4 space-y-3">
{messages.map((msg, i) => (
<MessageBubble key={i} message={msg} />
))}
{loading && (
<div className="flex justify-start">
<div className="bg-gray-800 rounded-2xl rounded-tl-sm px-4 py-3 flex gap-1 items-center">
<span className="w-2 h-2 bg-gray-400 rounded-full animate-bounce [animation-delay:0ms]" />
<span className="w-2 h-2 bg-gray-400 rounded-full animate-bounce [animation-delay:150ms]" />
<span className="w-2 h-2 bg-gray-400 rounded-full animate-bounce [animation-delay:300ms]" />
</div>
</div>
)}
<div ref={bottomRef} />
</div>
)
}
|