'use client'; import DeleteChat from '@/components/DeleteChat'; import { formatTimeDifference } from '@/lib/utils'; import { BookOpenText, ClockIcon, FileText, Globe2Icon } from 'lucide-react'; import Link from 'next/link'; import { useEffect, useState } from 'react'; export interface Chat { id: string; title: string; createdAt: string; sources: string[]; files: { fileId: string; name: string }[]; } const Page = () => { const [chats, setChats] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchChats = async () => { setLoading(true); const res = await fetch(`/api/chats`, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }); const data = await res.json(); setChats(data.chats); setLoading(false); }; fetchChats(); }, []); return (

Library

Past chats, sources, and uploads.
{loading ? 'Loading…' : `${chats.length} ${chats.length === 1 ? 'chat' : 'chats'}`}
{loading ? (
) : chats.length === 0 ? (

No chats found.

Start a new chat {' '} to see it listed here.

) : (
{chats.map((chat, index) => { const sourcesLabel = chat.sources.length === 0 ? null : chat.sources.length <= 2 ? chat.sources .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .join(', ') : `${chat.sources .slice(0, 2) .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .join(', ')} + ${chat.sources.length - 2}`; return (
{chat.title}
{formatTimeDifference(new Date(), chat.createdAt)} Ago {sourcesLabel && ( {sourcesLabel} )} {chat.files.length > 0 && ( {chat.files.length}{' '} {chat.files.length === 1 ? 'file' : 'files'} )}
); })}
)}
); }; export default Page;