import { useState, useEffect } from 'react'; import { Play, Copy, Trash2, Download, Clock } from 'lucide-react'; import { getGlobalReplaySystem } from '@/lib/infrastructure/ErrorReplay'; interface ReplayEntry { id: string; timestamp: string; error: string; type: string; } export function ReplaySection() { const [replays, setReplays] = useState([]); const [selectedReplay, setSelectedReplay] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { loadReplays(); }, []); const loadReplays = () => { const system = getGlobalReplaySystem(); const index = system.getReplayIndex(); setReplays(index); }; const handleReplay = async (replayId: string) => { setLoading(true); try { const system = getGlobalReplaySystem(); await system.replay(replayId); } catch (error) { console.error('Replay failed:', error); } finally { setLoading(false); } }; const handleExport = (replayId: string) => { const system = getGlobalReplaySystem(); const data = system.exportReplay(replayId, 'json'); const blob = new Blob([data], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `replay_${replayId}.json`; a.click(); URL.revokeObjectURL(url); }; const handleCopy = async (replayId: string) => { const system = getGlobalReplaySystem(); const data = system.exportReplay(replayId, 'json'); try { await navigator.clipboard.writeText(data); console.log('Replay data copied to clipboard'); } catch (err) { console.error('Failed to copy:', err); } }; const handleDelete = (replayId: string) => { if (confirm('Delete this replay?')) { const system = getGlobalReplaySystem(); system.deleteReplay(replayId); loadReplays(); } }; const handleClearAll = () => { if (confirm('Clear all replays?')) { const system = getGlobalReplaySystem(); system.clearAll(); loadReplays(); } }; return (
Error Replay
{replays.length === 0 ? (
No replays available
) : (
{replays.map((replay) => (
{replay.type}
{replay.error}
{new Date(replay.timestamp).toLocaleTimeString()}
))}
)}
); }