From aeb33058bba0327348f71cc995ea487ed0fc242b Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Wed, 29 Apr 2020 20:55:52 +1000 Subject: [PATCH] Added erase all back in --- src/components/map/Map.js | 20 +++++++++++-------- src/components/map/MapControls.js | 2 ++ .../map/controls/EraseToolSettings.js | 8 ++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/components/map/Map.js b/src/components/map/Map.js index 8b482a9..502c694 100644 --- a/src/components/map/Map.js +++ b/src/components/map/Map.js @@ -63,6 +63,7 @@ function Map({ useBlending: true, }, }); + function handleToolSettingChange(tool, change) { setToolSettings((prevSettings) => ({ ...prevSettings, @@ -73,6 +74,16 @@ function Map({ })); } + function handleToolAction(action) { + if (action === "eraseAll") { + onMapDraw({ + type: "remove", + shapeIds: mapShapes.map((s) => s.id), + timestamp: Date.now(), + }); + } + } + const [mapShapes, setMapShapes] = useState([]); function handleMapShapeAdd(shape) { onMapDraw({ type: "add", shapes: [shape], timestamp: Date.now() }); @@ -82,14 +93,6 @@ function Map({ onMapDraw({ type: "remove", shapeIds: [shapeId], timestamp: Date.now() }); } - function handleShapeRemoveAll() { - onMapDraw({ - type: "remove", - shapeIds: mapShapes.map((s) => s.id), - timestamp: Date.now(), - }); - } - const [fogShapes, setFogShapes] = useState([]); function handleFogShapeAdd(shape) { onFogDraw({ type: "add", shapes: [shape], timestamp: Date.now() }); @@ -251,6 +254,7 @@ function Map({ selectedToolId={selectedToolId} toolSettings={toolSettings} onToolSettingChange={handleToolSettingChange} + onToolAction={handleToolAction} disabledControls={disabledControls} onUndo={onMapUndo} onRedo={onMapRedo} diff --git a/src/components/map/MapControls.js b/src/components/map/MapControls.js index b5429ed..4d7d311 100644 --- a/src/components/map/MapControls.js +++ b/src/components/map/MapControls.js @@ -28,6 +28,7 @@ function MapContols({ onSelectedToolChange, toolSettings, onToolSettingChange, + onToolAction, disabledControls, onUndo, onRedo, @@ -192,6 +193,7 @@ function MapContols({ onSettingChange={(change) => onToolSettingChange(selectedToolId, change) } + onToolAction={onToolAction} /> ); diff --git a/src/components/map/controls/EraseToolSettings.js b/src/components/map/controls/EraseToolSettings.js index f418bed..01a2aeb 100644 --- a/src/components/map/controls/EraseToolSettings.js +++ b/src/components/map/controls/EraseToolSettings.js @@ -3,10 +3,14 @@ import { Flex, IconButton } from "theme-ui"; import EraseAllIcon from "../../../icons/EraseAllIcon"; -function EraseToolSettings({ onEraseAll }) { +function EraseToolSettings({ onToolAction }) { return ( - + onToolAction("eraseAll")} + >