import { useEffect } from 'react' import { motion as m } from 'framer-motion' import { useAtomValue } from 'jotai' import { GalleryHorizontalEndIcon, MoreVerticalIcon, Trash2Icon, Paintbrush, } from 'lucide-react' import { twMerge } from 'tailwind-merge' import { useCreateNewThread } from '@/hooks/useCreateNewThread' import useDeleteThread from '@/hooks/useDeleteThread' import useGetAllThreads from '@/hooks/useGetAllThreads' import useGetAssistants from '@/hooks/useGetAssistants' import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels' import useSetActiveThread from '@/hooks/useSetActiveThread' import { displayDate } from '@/utils/datetime' import { activeThreadAtom, threadStatesAtom, threadsAtom, } from '@/helpers/atoms/Thread.atom' export default function ThreadList() { const threads = useAtomValue(threadsAtom) const threadStates = useAtomValue(threadStatesAtom) const { getAllThreads } = useGetAllThreads() const { assistants } = useGetAssistants() const { requestCreateNewThread } = useCreateNewThread() const activeThread = useAtomValue(activeThreadAtom) const { deleteThread, cleanThread } = useDeleteThread() const { downloadedModels } = useGetDownloadedModels() const { activeThreadId, setActiveThread: onThreadClick } = useSetActiveThread() useEffect(() => { getAllThreads() // eslint-disable-next-line react-hooks/exhaustive-deps }, []) useEffect(() => { if ( downloadedModels.length !== 0 && threads.length === 0 && assistants.length !== 0 && !activeThread ) { requestCreateNewThread(assistants[0]) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [assistants, threads, downloadedModels, activeThread]) return (
{threads.length === 0 ? (

No Thread History

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

{thread.title}

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

{lastMessage || 'No new message'}

cleanThread(thread.id)} > Clean thread
deleteThread(thread.id)} > Delete thread
{/* {messages.length > 0 && ( )} */} {activeThreadId === thread.id && ( )}
) }) )}
) }