'use client'; import { useState, useEffect } from 'react'; import { X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { DiffViewer } from './diff-viewer'; interface HistoryEntry { id: string; oldContent: string; newContent: string; reason: string; createdAt: string; } interface HistoryModalProps { slug: string; isOpen: boolean; onClose: () => void; } export function HistoryModal({ slug, isOpen, onClose }: HistoryModalProps) { const [history, setHistory] = useState([]); const [isLoading, setIsLoading] = useState(true); const [selectedEntry, setSelectedEntry] = useState(null); useEffect(() => { if (!isOpen) return; const fetchHistory = async () => { setIsLoading(true); try { const response = await fetch(`/api/article/${encodeURIComponent(slug)}/history`); if (response.ok) { const data = await response.json(); setHistory(data); if (data.length > 0) { setSelectedEntry(data[0]); } } } catch (error) { console.error('Failed to fetch history:', error); } finally { setIsLoading(false); } }; fetchHistory(); }, [slug, isOpen]); if (!isOpen) return null; const formatDate = (dateString: string) => { return new Date(dateString).toLocaleString(); }; return (
e.stopPropagation()}>

Revision History

{isLoading ? (
Loading history...
) : history.length === 0 ? (
No revision history available.
) : ( <>
{history.map((entry) => ( ))}
{selectedEntry && ( )}
)}
); }