import React, { useEffect, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Trash2, ExternalLink, Calendar, Loader2 } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; import { getScanHistory, deleteScan } from '../services/api'; // We'll add these import { cn } from '../utils'; export const ScanHistory = ({ onSelectScan }) => { const { user, isPremium, getToken } = useAuth(); const [scans, setScans] = useState([]); const [loading, setLoading] = useState(true); const [deletingId, setDeletingId] = useState(null); const limit = isPremium ? 30 : 5; const usage = scans.length; const isOverLimit = usage >= limit; useEffect(() => { if (user) { loadHistory(); } }, [user]); const loadHistory = async () => { try { setLoading(true); const token = await getToken(); const data = await getScanHistory(token); setScans(data || []); } catch (err) { console.error('Failed to load history', err); } finally { setLoading(false); } }; const handleDelete = async (e, id) => { e.stopPropagation(); if (!confirm('Are you sure you want to delete this scan?')) return; try { setDeletingId(id); await deleteScan(id, await getToken()); setScans(prev => prev.filter(s => s.id !== id)); } catch (err) { console.error('Failed to delete', err); alert('Failed to delete scan'); } finally { setDeletingId(null); } }; if (!user) return null; return (

History of Shame

Your past roasts. Relive the trauma.

{/* Usage Meter */}
Storage Usage {usage} / {limit}
{isOverLimit && (
Storage limit reached!
)}
{loading ? (
) : scans.length === 0 ? (

No roasts yet. Go judge something!

) : (
{scans.map((scan) => ( onSelectScan(scan)} className="group cursor-pointer relative bg-white border-2 border-brutalist-black p-4 shadow-hard-sm hover:shadow-hard-lg transition-all" >
{scan.personality}

{scan.url.replace(/^https?:\/\/(www\.)?/, '')}

{new Date(scan.created_at).toLocaleDateString()}
"{scan.roast_data?.critique?.substring(0, 100)}..."
View Report
))}
)}
); };