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

Library


{chats.length === 0 && (

No chats found.

)} {chats.length > 0 && (
{chats.map((chat, i) => (
{chat.title}

{formatTimeDifference(new Date(), chat.createdAt)} Ago

))}
)}
); }; export default Page;