import { useEffect } from 'react' import { Button } from '@janhq/uikit' import { motion as m } from 'framer-motion' import { useAtomValue } from 'jotai' import { GalleryHorizontalEndIcon } from 'lucide-react' import { twMerge } from 'tailwind-merge' import { useCreateNewThread } from '@/hooks/useCreateNewThread' import useGetAllThreads from '@/hooks/useGetAllThreads' import useGetAssistants from '@/hooks/useGetAssistants' import useSetActiveThread from '@/hooks/useSetActiveThread' import { displayDate } from '@/utils/datetime' import { threadStatesAtom, threadsAtom, } from '@/helpers/atoms/Conversation.atom' export default function ThreadList() { const threads = useAtomValue(threadsAtom) const threadStates = useAtomValue(threadStatesAtom) const { requestCreateNewThread } = useCreateNewThread() const { assistants } = useGetAssistants() const { getAllThreads } = useGetAllThreads() const { activeThreadId, setActiveThread: onThreadClick } = useSetActiveThread() useEffect(() => { getAllThreads() }, []) const onCreateConversationClick = async () => { if (assistants.length === 0) { alert('No assistant available') return } requestCreateNewThread(assistants[0]) } return (
{threads.length === 0 ? (

No Chat History

Get started by creating a new chat

) : ( threads.map((thread, i) => { const lastMessage = threadStates[thread.id]?.lastMessage ?? '' return (
onThreadClick(thread)} >

{thread.updated && displayDate(new Date(thread.updated).getTime())}

{thread.title}

{lastMessage}

{activeThreadId === thread.id && ( )}
) }) )}
) }