feat: clear blocks history entry
This commit is contained in:
parent
9f07754ab7
commit
b59175f24d
1 changed files with 12 additions and 1 deletions
|
|
@ -1,15 +1,26 @@
|
|||
import { useContext } from "react";
|
||||
|
||||
import { CanvasContext } from "@/context/Canvas";
|
||||
import { HistoryContext } from "@/context/History";
|
||||
|
||||
import { DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
function ClearBlocks({ close }: DialogProps) {
|
||||
const { setBlocks } = useContext(CanvasContext);
|
||||
const { addHistory } = useContext(HistoryContext);
|
||||
|
||||
const onSubmit = () => {
|
||||
setBlocks([{ name: "bedrock", x: 0, y: 0 }]);
|
||||
const clearedBlocks = [{ name: "bedrock", x: 0, y: 0 }];
|
||||
setBlocks((prev) => {
|
||||
addHistory(
|
||||
"Clear All",
|
||||
() => setBlocks(clearedBlocks),
|
||||
() => setBlocks(prev)
|
||||
);
|
||||
return clearedBlocks;
|
||||
});
|
||||
|
||||
close();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue