import React, { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { MessageSquare, Trash2 } from 'lucide-react'; import { Button } from '../../components/ui/Button'; import { useAuth } from '../../contexts/AuthContext'; import { chatService } from '../../lib/chat-service'; import type { ChatInstance } from '../../types/supabase'; export default function StudyHistory() { const { user } = useAuth(); const [chats, setChats] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { if (!user) return; const loadChats = async () => { const chatInstances = await chatService.getChatInstances(user.id); setChats(chatInstances); setLoading(false); }; loadChats(); }, [user]); const handleDelete = async (chatId: string) => { const success = await chatService.deleteChatInstance(chatId); if (success) { setChats(prev => prev.filter(chat => chat.id !== chatId)); } }; if (loading) { return (
Loading...
); } return (

Study History

View your past conversations

{chats.length === 0 ? (

No chat history

Start a new conversation to see it here

) : (
{chats.map((chat) => (

{chat.title}

Last updated: {new Date(chat.last_message_at).toLocaleString()}

))}
)}
); }