diff --git a/src/App.tsx b/src/App.tsx index 11d6e30..157fcb9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef, useState } from "react"; import { Layer, Stage } from "react-konva"; -import { Hand, Pencil } from "lucide-react"; +import { Eraser, Hand, Pencil } from "lucide-react"; import { Menubar, @@ -92,15 +92,15 @@ function App() { }; const onClick = (e) => { + const blockX = Math.floor(mousePosition.x / 16); + const blockY = Math.floor(mousePosition.y / 16); + const updatedBlocks = blocks.filter((b) => !(b.x === blockX && b.y === blockY)); + switch (tool) { case "hand": setCssCursor("grabbing"); break; case "pencil": { - const blockX = Math.floor(mousePosition.x / 16); - const blockY = Math.floor(mousePosition.y / 16); - const updatedBlocks = blocks.filter((b) => !(b.x === blockX && b.y === blockY)); - setBlocks([ ...updatedBlocks, { @@ -109,6 +109,11 @@ function App() { y: blockY, }, ]); + break; + } + case "eraser": { + setBlocks(updatedBlocks); + break; } } }; @@ -158,10 +163,9 @@ function App() { @@ -169,6 +173,9 @@ function App() { + + +
diff --git a/src/types.d.ts b/src/types.d.ts index c013d71..43f237b 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -7,4 +7,4 @@ interface Block extends Position { name: string; } -type Tool = "hand" | "pencil"; \ No newline at end of file +type Tool = "hand" | "pencil" | "eraser"; \ No newline at end of file