"use client"; import { useEffect, useRef, useCallback } from "react"; import { useChatStore } from "@/lib/store"; import { Message } from "./message"; export function MessageList() { const messages = useChatStore((s) => s.messages); const isStreaming = useChatStore((s) => s.isStreaming); const containerRef = useRef(null); const isNearBottomRef = useRef(true); const scrollToBottom = useCallback(() => { if (!containerRef.current || !isNearBottomRef.current) return; containerRef.current.scrollTop = containerRef.current.scrollHeight; }, []); const handleScroll = useCallback(() => { if (!containerRef.current) return; const { scrollTop, scrollHeight, clientHeight } = containerRef.current; isNearBottomRef.current = scrollHeight - scrollTop - clientHeight < 100; }, []); useEffect(() => { scrollToBottom(); }, [messages, scrollToBottom]); if (messages.length === 0) { return (

aeries

say something

); } return (
{messages.map((msg, i) => { const next = messages[i + 1]; const isLastInGroup = !next || next.role !== msg.role; const isCurrentlyStreaming = isStreaming && msg.role === "assistant" && i === messages.length - 1; return ( ); })}
); }