From 6e48d7d4e213d644cc74082ecebcc6f2c0cf1f5c Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Wed, 29 Apr 2020 09:25:56 +1000 Subject: [PATCH] Fix drawing erase while on controls and brush type switch bug --- src/components/map/MapDrawing.js | 10 +++++----- src/components/map/MapFog.js | 10 +++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/map/MapDrawing.js b/src/components/map/MapDrawing.js index 29c1203..84bddba 100644 --- a/src/components/map/MapDrawing.js +++ b/src/components/map/MapDrawing.js @@ -155,19 +155,19 @@ function MapDrawing({ if (event.touches && event.touches.length !== 0) { return; } - setIsDrawing(false); - if (selectedTool === "brush") { + if (selectedTool === "brush" && drawingShape) { if (drawingShape.data.points.length > 1) { onShapeAdd(drawingShape); } - } else if (selectedTool === "shape") { + } else if (selectedTool === "shape" && drawingShape) { onShapeAdd(drawingShape); } - setDrawingShape(null); - if (selectedTool === "erase" && hoveredShapeRef.current) { + if (selectedTool === "erase" && hoveredShapeRef.current && isDrawing) { onShapeRemove(hoveredShapeRef.current.id); } + setIsDrawing(false); + setDrawingShape(null); } // Add listeners for draw events on map to allow drawing past the bounds diff --git a/src/components/map/MapFog.js b/src/components/map/MapFog.js index 28d2e35..1f06701 100644 --- a/src/components/map/MapFog.js +++ b/src/components/map/MapFog.js @@ -122,7 +122,6 @@ function MapFog({ if (event.touches && event.touches.length !== 0) { return; } - setIsDrawing(false); if (isEditing && toolSettings.type === "add" && drawingShape) { if (drawingShape.data.points.length > 1) { const shape = { @@ -134,10 +133,15 @@ function MapFog({ } } - setDrawingShape(null); - if (toolSettings.type === "remove" && hoveredShapeRef.current) { + if ( + toolSettings.type === "remove" && + hoveredShapeRef.current && + isDrawing + ) { onShapeRemove(hoveredShapeRef.current.id); } + setDrawingShape(null); + setIsDrawing(false); } // Add listeners for draw events on map to allow drawing past the bounds