This commit is contained in:
1ilit 2023-09-19 15:49:43 +03:00
parent 2cfcc94a5d
commit 59609b1cd8

View File

@ -417,7 +417,7 @@ export default function ControlPanel(props) {
setNotes(data.notes); setNotes(data.notes);
}; };
const addTable = () =>{ const addTable = () => {
setTables((prev) => [ setTables((prev) => [
...prev, ...prev,
{ {
@ -443,33 +443,33 @@ export default function ControlPanel(props) {
color: defaultTableTheme, color: defaultTableTheme,
}, },
]); ]);
setUndoStack((prev)=>[...prev, { };
action: "add",
element: "table",
}])
}
const undo = () =>{ const undo = () => {
if(undoStack.length===0) return; if (undoStack.length === 0) return;
const a = undoStack.pop(); const a = undoStack.pop();
if(a.action==="add"){ if (a.action === "add") {
if(a.element==="table"){ if (a.element === "table") {
setTables(prev=>prev.filter(e=>e.id!==prev.length-1).map((e, i)=>({...e, id: i}))) setTables((prev) =>
prev
.filter((e) => e.id !== prev.length - 1)
.map((e, i) => ({ ...e, id: i }))
);
} }
} }
setRedoStack(prev=>[...prev, a]) setRedoStack((prev) => [...prev, a]);
} };
const redo = () =>{ const redo = () => {
if(redoStack.length===0) return; if (redoStack.length === 0) return;
const a = redoStack.pop(); const a = redoStack.pop();
if(a.action==="add"){ if (a.action === "add") {
if(a.element==="table"){ if (a.element === "table") {
addTable(); addTable();
} }
} }
setUndoStack(prev=>[...prev, a]) setUndoStack((prev) => [...prev, a]);
} };
return ( return (
<div> <div>
@ -558,7 +558,17 @@ export default function ControlPanel(props) {
<button <button
className="flex items-center py-1 px-2 hover:bg-slate-200 rounded" className="flex items-center py-1 px-2 hover:bg-slate-200 rounded"
title="Add new table" title="Add new table"
onClick={addTable} onClick={() => {
addTable();
setUndoStack((prev) => [
...prev,
{
action: "add",
element: "table",
},
]);
if (redoStack.length > 0) setRedoStack([]);
}}
> >
<AddTable /> <AddTable />
</button> </button>