wuyiqunLu
feat: support internal access to all chat (#45)
5411802 unverified
raw
history blame
No virus
2.02 kB
'use client';
import { ChatList } from '@/components/chat/ChatList';
import { Composer } from '@/components/chat/Composer';
import { ChatEntity } from '@/lib/types';
import useVisionAgent from '@/lib/hooks/useVisionAgent';
import { useScrollAnchor } from '@/lib/hooks/useScrollAnchor';
import { Session } from 'next-auth';
import { useState } from 'react';
export interface ChatProps extends React.ComponentProps<'div'> {
chat: ChatEntity;
isAdminView?: boolean;
session: Session | null;
}
export function Chat({ chat, session, isAdminView }: ChatProps) {
const { url, id } = chat;
const [enableSelfReflection, setEnableSelfReflection] =
useState<boolean>(true);
const { messages, append, reload, stop, isLoading, input, setInput } =
useVisionAgent(chat, enableSelfReflection);
const { messagesRef, scrollRef, visibilityRef, isAtBottom, scrollToBottom } =
useScrollAnchor();
return (
<>
<div className="h-full overflow-auto relative" ref={scrollRef}>
<div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
<ChatList
messages={messages}
session={session}
isLoading={isLoading}
/>
<div className="h-px w-full" ref={visibilityRef} />
</div>
</div>
{!isAdminView && (
<div className="fixed inset-x-0 bottom-0 w-full animate-in duration-300 ease-in-out peer-[[data-state=open]]:group-[]:lg:pl-[250px] peer-[[data-state=open]]:group-[]:xl:pl-[300px] h-[178px]">
<Composer
id={id}
url={url}
isLoading={isLoading}
stop={stop}
append={append}
reload={reload}
messages={messages}
input={input}
setInput={setInput}
isAtBottom={isAtBottom}
scrollToBottom={scrollToBottom}
enableSelfReflection={enableSelfReflection}
setEnableSelfReflection={setEnableSelfReflection}
/>
</div>
)}
</>
);
}