import { useEffect } from 'react' import { Thread, Model } from '@janhq/core' import { Button } from '@janhq/uikit' import { motion as m } from 'framer-motion' import { useAtomValue, useSetAtom } from 'jotai' import { GalleryHorizontalEndIcon } from 'lucide-react' import { twMerge } from 'tailwind-merge' import { useActiveModel } from '@/hooks/useActiveModel' import { useCreateConversation } from '@/hooks/useCreateConversation' import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels' import useGetUserConversations from '@/hooks/useGetUserConversations' import { displayDate } from '@/utils/datetime' import { getActiveConvoIdAtom, setActiveConvoIdAtom, userConversationsAtom, } from '@/helpers/atoms/Conversation.atom' export default function HistoryList() { const conversations = useAtomValue(userConversationsAtom) const { getUserConversations } = useGetUserConversations() const { activeModel, startModel } = useActiveModel() const { requestCreateConvo } = useCreateConversation() const activeConvoId = useAtomValue(getActiveConvoIdAtom) const setActiveConvoId = useSetAtom(setActiveConvoIdAtom) const { downloadedModels } = useGetDownloadedModels() useEffect(() => { getUserConversations() // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const handleClickConversation = () => { if (activeModel) requestCreateConvo(activeModel as Model) return } const handleActiveModel = async (convo: Thread) => { if (convo.modelId == null) { console.debug('modelId is undefined') return } const model = downloadedModels.find((e) => e.id === convo.modelId) if (convo == null) { console.debug('modelId is undefined') return } if (model != null) { startModel(model.id) } if (activeConvoId !== convo.id) { setActiveConvoId(convo.id) } } return (
Get started by creating a new chat
{convo.updatedAt && displayDate(new Date(convo.updatedAt).getTime())}
{/* TODO: Check latest message update */} {convo?.messages[0]?.content ?? 'No new message'}
{activeModel && activeConvoId === convo.id && (