File size: 1,727 Bytes
f3a9ef2
a86b547
1f931d5
bfbf1a7
a86b547
8e3dbd3
58d7e55
34afd2e
5ec491a
1f931d5
f3a9ef2
1f931d5
5ec491a
f3a9ef2
 
1f931d5
5ec491a
f80b091
d553ae5
f3a9ef2
8e3dbd3
 
 
f80b091
1f931d5
2c2b487
1f931d5
 
 
 
 
 
 
 
 
 
 
 
 
f80b091
1f931d5
 
 
 
 
 
 
 
 
 
 
 
 
 
f80b091
1f931d5
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'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 { Session } from 'next-auth';
import { useState } from 'react';
import { ChatWithMessages } from '@/lib/db/types';
import { ChatMessage } from './ChatMessage';

export interface ChatClientProps {
  chat: ChatWithMessages;
}

const ChatClient: React.FC<ChatClientProps> = ({ chat }) => {
  const { mediaUrl, id } = chat;
  const { messages, append, reload, stop, isLoading, input, setInput } =
    useVisionAgent(chat);

  const { messagesRef, scrollRef, visibilityRef, isAtBottom, scrollToBottom } =
    useScrollAnchor();

  return (
    <div
      className="h-full overflow-auto mx-auto max-w-5xl min-w-3xl border rounded-lg"
      ref={scrollRef}
    >
      <div className="overflow-auto h-full pt-6 px-6" ref={messagesRef}>
        {messages
          // .filter(message => message.role !== 'system')
          .map((message, index) => (
            <ChatMessage
              key={index}
              message={message}
              isLoading={isLoading && index === messages.length - 1}
            />
          ))}
        <div className="h-px w-full" ref={visibilityRef} />
      </div>
      <div className="sticky bottom-3 w-full">
        <Composer
          id={id}
          mediaUrl={mediaUrl}
          isLoading={isLoading}
          stop={stop}
          append={append}
          reload={reload}
          messages={messages}
          input={input}
          setInput={setInput}
        />
      </div>
    </div>
  );
};

export default ChatClient;