import React, { useEffect, useState } from 'react'; import UndoCard from './components/UndoCard'; interface ModificationHistory { ID: number; DocumentID: number; DateChanged: string; ModField: string; PreviousValue: string; NewValue: string; Undone: boolean; UndoneDate: string | null; } const History: React.FC = () => { const [modifications, setModifications] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [paperlessUrl, setPaperlessUrl] = useState(''); // Get Paperless URL useEffect(() => { const fetchUrl = async () => { try { const response = await fetch('/api/paperless-url'); if (!response.ok) { throw new Error('Failed to fetch public URL'); } const { url } = await response.json(); setPaperlessUrl(url); } catch (err) { console.error('Error fetching Paperless URL:', err); } }; fetchUrl(); }, []); // Get all modifications useEffect(() => { fetchModifications(); }, []); const fetchModifications = async () => { try { const response = await fetch('/api/modifications'); if (!response.ok) { throw new Error('Failed to fetch modifications'); } const data = await response.json(); setModifications(data); } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error occurred'); } finally { setLoading(false); } }; const handleUndo = async (id: number) => { try { const response = await fetch(`/api/undo-modification/${id}`, { method: 'POST', }); if (!response.ok) { throw new Error('Failed to undo modification'); } // Use ISO 8601 format for consistency const now = new Date().toISOString(); setModifications(mods => mods.map(mod => mod.ID === id ? { ...mod, Undone: true, UndoneDate: now } : mod )); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to undo modification'); } }; if (loading) { return (
); } if (error) { return (
Error: {error}
); } return (

Modification History

Note: when undoing tag changes, this will not re-add 'paperless-gpt-auto'
{modifications.length === 0 ? (

No modifications found

) : (
{modifications.map((modification) => ( ))}
)}
); }; export default History;