mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:45:24 +02:00
feat: persistent multi-step undo system in TopBar
This commit is contained in:
+8
-3
@@ -275,8 +275,8 @@ export default function App() {
|
|||||||
data: JSON.parse(JSON.stringify(appState.data)), // Deep copy
|
data: JSON.parse(JSON.stringify(appState.data)), // Deep copy
|
||||||
message
|
message
|
||||||
};
|
};
|
||||||
// Keep only last 5 steps
|
// Keep last 50 steps
|
||||||
const newHistory = [newState, ...prev].slice(0, 5);
|
const newHistory = [newState, ...prev].slice(0, 50);
|
||||||
return newHistory;
|
return newHistory;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -412,7 +412,12 @@ export default function App() {
|
|||||||
<UndoToast
|
<UndoToast
|
||||||
undoState={undoHistory[0] || null}
|
undoState={undoHistory[0] || null}
|
||||||
onUndo={handleUndo}
|
onUndo={handleUndo}
|
||||||
onClose={() => setUndoHistory([])}
|
onClose={() => {
|
||||||
|
// Instead of clearing history, we can just hide the toast
|
||||||
|
// But since UndoToast is driven by undoHistory[0],
|
||||||
|
// we might want a way to "acknowledge" the current top of history
|
||||||
|
// For now, let's just not clear the history.
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{editingRowIndex !== null && (
|
{editingRowIndex !== null && (
|
||||||
|
|||||||
+20
-15
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Download, Database, LogOut, Undo2 } from 'lucide-react';
|
import { Download, Database, LogOut, Undo2 } from 'lucide-react';
|
||||||
|
import { cn } from '../lib/utils';
|
||||||
|
|
||||||
interface TopBarProps {
|
interface TopBarProps {
|
||||||
stats: any;
|
stats: any;
|
||||||
@@ -70,21 +71,25 @@ export function TopBar({ stats, onExport, hasData, hasUnsavedChanges, userEmail,
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{canUndo && (
|
<button
|
||||||
<button
|
onClick={onUndo}
|
||||||
onClick={onUndo}
|
disabled={!canUndo}
|
||||||
title={`Undo: ${undoMessage}`}
|
title={canUndo ? `Undo: ${undoMessage}` : 'No changes to undo'}
|
||||||
className="flex items-center gap-2 px-4 py-2 bg-amber-600 hover:bg-amber-700 text-white rounded-md text-sm font-bold transition-all shadow-lg shadow-amber-900/40 animate-in fade-in zoom-in duration-300 relative group"
|
className={cn(
|
||||||
>
|
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-bold transition-all shadow-lg relative group",
|
||||||
<Undo2 className="w-4 h-4" />
|
canUndo
|
||||||
BACK / UNDO
|
? "bg-amber-600 hover:bg-amber-700 text-white shadow-amber-900/40 cursor-pointer"
|
||||||
{undoSteps > 1 && (
|
: "bg-slate-800 text-slate-600 shadow-none cursor-not-allowed opacity-50"
|
||||||
<span className="absolute -top-1 -right-1 bg-white text-amber-700 text-[10px] w-4 h-4 rounded-full flex items-center justify-center shadow-md">
|
)}
|
||||||
{undoSteps}
|
>
|
||||||
</span>
|
<Undo2 className="w-4 h-4" />
|
||||||
)}
|
BACK / UNDO
|
||||||
</button>
|
{canUndo && undoSteps > 1 && (
|
||||||
)}
|
<span className="absolute -top-1 -right-1 bg-white text-amber-700 text-[10px] w-4 h-4 rounded-full flex items-center justify-center shadow-md font-bold">
|
||||||
|
{undoSteps}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
{userEmail && (
|
{userEmail && (
|
||||||
<div className="flex items-center gap-2 border-l border-slate-700 pl-3">
|
<div className="flex items-center gap-2 border-l border-slate-700 pl-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user