From c67fcadb4894f865dcc9aa852ad5766558b89e4c Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Sun, 29 Mar 2026 17:50:31 +0200 Subject: [PATCH] Enhance Undo system with 5-step history and TopBar badge --- src/App.tsx | 30 +++++++++++++++++++----------- src/components/TopBar.tsx | 10 ++++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 3879e97..cfdce67 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,7 +32,7 @@ export default function App() { hasUnsavedChanges: false }); const [activeModule, setActiveModule] = useState<'descriptions' | 'matrix' | 'dimensions'>('descriptions'); - const [undoState, setUndoState] = useState<{ data: ExcelRow[], message: string } | null>(null); + const [undoHistory, setUndoHistory] = useState<{ data: ExcelRow[], message: string }[]>([]); const [editingRowIndex, setEditingRowIndex] = useState(null); const [isLoadingDefault, setIsLoadingDefault] = useState(true); const [defaultLoadError, setDefaultLoadError] = useState(null); @@ -248,20 +248,27 @@ export default function App() { }; const captureState = (message: string) => { - setUndoState({ - data: JSON.parse(JSON.stringify(appState.data)), // Deep copy - message + setUndoHistory(prev => { + const newState = { + data: JSON.parse(JSON.stringify(appState.data)), // Deep copy + message + }; + // Keep only last 5 steps + const newHistory = [newState, ...prev].slice(0, 5); + return newHistory; }); }; const handleUndo = () => { - if (!undoState) return; + if (undoHistory.length === 0) return; + + const [lastAction, ...remainingHistory] = undoHistory; setAppState(prev => ({ ...prev, - data: undoState.data, + data: lastAction.data, hasUnsavedChanges: true })); - setUndoState(null); + setUndoHistory(remainingHistory); }; const stats = useMemo(() => { @@ -305,9 +312,10 @@ export default function App() { hasUnsavedChanges={appState.hasUnsavedChanges} userEmail={session.user.email} onSignOut={handleSignOut} - canUndo={!!undoState} + canUndo={undoHistory.length > 0} onUndo={handleUndo} - undoMessage={undoState?.message} + undoMessage={undoHistory[0]?.message} + undoSteps={undoHistory.length} />
@@ -360,9 +368,9 @@ export default function App() {
setUndoState(null)} + onClose={() => setUndoHistory([])} /> {editingRowIndex !== null && ( diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index c6c81aa..e597d6f 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -11,9 +11,10 @@ interface TopBarProps { canUndo: boolean; onUndo: () => void; undoMessage?: string; + undoSteps: number; } -export function TopBar({ stats, onExport, hasData, hasUnsavedChanges, userEmail, onSignOut, canUndo, onUndo, undoMessage }: TopBarProps) { +export function TopBar({ stats, onExport, hasData, hasUnsavedChanges, userEmail, onSignOut, canUndo, onUndo, undoMessage, undoSteps }: TopBarProps) { return (
@@ -73,10 +74,15 @@ export function TopBar({ stats, onExport, hasData, hasUnsavedChanges, userEmail, )}