Spaces:
Sleeping
Sleeping
File size: 1,819 Bytes
4af6326 c7e97b5 4af6326 db06845 4af6326 db06845 c7e97b5 4af6326 c7e97b5 4af6326 7286745 4af6326 3c8b24f db06845 4af6326 |
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 |
'use client';
import { ChatWithMessages } from '@/lib/types';
import React, { useEffect } from 'react';
import ChatList from './chat/ChatList';
import { Card } from './ui/Card';
import { useAtom, useAtomValue } from 'jotai';
import { selectedMessageId } from '@/state/chat';
import CodeResultDisplay from './CodeResultDisplay';
export interface ChatInterfaceProps {
chat: ChatWithMessages;
userId?: string | null;
}
const ChatInterface: React.FC<ChatInterfaceProps> = ({ chat, userId }) => {
const [messageId, setMessageId] = useAtom(selectedMessageId);
const messageCodeResult = chat.messages.find(
message => message.id === messageId,
)?.result;
useEffect(() => {
if (messageId) return;
const lastMessageWithResult =
chat.messages.findLast(message => !!message.result) ??
chat.messages[chat.messages.length - 1];
setMessageId(lastMessageWithResult?.id);
}, [messageId]);
return (
<div className="relative flex overflow-hidden space-x-4 size-full">
<div
data-state={messageCodeResult?.payload ? 'open' : 'closed'}
className="pl-4 peer absolute right-0 inset-y-0 hidden translate-x-full data-[state=open]:translate-x-0 z-30 duration-300 ease-in-out xl:flex flex-col items-start xl:w-1/2 h-full dark:bg-zinc-950 overflow-auto"
>
{messageCodeResult?.type === 'final_code' &&
messageCodeResult.payload && (
<Card className="size-full overflow-auto">
<CodeResultDisplay codeResult={messageCodeResult.payload} />
</Card>
)}
</div>
<div className="w-full flex justify-center pr-0 animate-in duration-300 ease-in-out peer-[[data-state=open]]:xl:pr-[50%]">
<ChatList chat={chat} userId={userId} />
</div>
</div>
);
};
export default ChatInterface;
|