'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'; import { toast } from 'sonner'; import { getApiUrl, get } from '@/lib/api'; 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); try { const data = await get<{ chats: Chat[] }>(getApiUrl('/chats')); setChats(data.chats); } catch (error) { console.error('获取聊天记录失败:', error); toast.error('获取聊天记录失败'); } finally { 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;