import { useEffect } from 'react' import { Modal, ModalTrigger, ModalClose, ModalFooter, ModalPortal, ModalContent, ModalHeader, ModalTitle, Button, } from '@janhq/uikit' 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 useGetAssistants from '@/hooks/useGetAssistants' import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels' import useSetActiveThread from '@/hooks/useSetActiveThread' import useThreads from '@/hooks/useThreads' 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 { getThreads } = useThreads() const { assistants } = useGetAssistants() const { requestCreateNewThread } = useCreateNewThread() const activeThread = useAtomValue(activeThreadAtom) const { deleteThread, cleanThread } = useDeleteThread() const { downloadedModels } = useGetDownloadedModels() const { activeThreadId, setActiveThread: onThreadClick } = useSetActiveThread() useEffect(() => { getThreads() // 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 (
{thread.updated && displayDate(new Date(thread.updated).getTime())}
{lastMessage || 'No new message'}
Are you sure you want to clean this thread?
Are you sure you want to delete this thread? This action cannot be undone.