'use client'; // import { ChatList } from '@/components/chat/ChatList'; import Composer from '@/components/chat/Composer'; import useVisionAgent from '@/lib/hooks/useVisionAgent'; import { useScrollAnchor } from '@/lib/hooks/useScrollAnchor'; import { useEffect } from 'react'; import { ChatWithMessages } from '@/lib/types'; import { ChatMessage } from './ChatMessage'; import { Button } from '../ui/Button'; import { cn } from '@/lib/utils'; import { IconArrowDown } from '../ui/Icons'; import { dbPostCreateMessage } from '@/lib/db/functions'; import { Card } from '../ui/Card'; export interface ChatListProps { chat: ChatWithMessages; userId?: string | null; } export const SCROLL_BOTTOM = 120; const ChatList: React.FC = ({ chat, userId }) => { const { id, messages: dbMessages, userId: chatUserId } = chat; const { isLoading, data } = useVisionAgent(chat); // Only login and chat owner can compose const canCompose = !chatUserId || userId === chatUserId; const { messagesRef, scrollRef, visibilityRef, isVisible, scrollToBottom } = useScrollAnchor(SCROLL_BOTTOM); // Scroll to bottom on init useEffect(() => { scrollToBottom(); }, [scrollToBottom]); return (
{dbMessages.map((message, index) => { const isLastMessage = index === dbMessages.length - 1; return ( 0 ? data : undefined } /> ); })}
{canCompose && (
{ const messageInput = { prompt: input, mediaUrl: newMediaUrl, }; await dbPostCreateMessage(id, messageInput); }} />
)} {/* Scroll to bottom Icon */} ); }; export default ChatList;