From 06f5d3ab42ce5be76008ff7a5f22076bd47b0e93 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Mon, 20 Apr 2020 15:31:54 +1000 Subject: [PATCH] Added auto switch away from a disabled tool --- src/components/MapControls.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/MapControls.js b/src/components/MapControls.js index d6c2a07..c980384 100644 --- a/src/components/MapControls.js +++ b/src/components/MapControls.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Flex, Box, IconButton, Label } from "theme-ui"; import AddMapButton from "./AddMapButton"; @@ -145,6 +145,13 @@ function MapControls({ } } + // Detect when a tool becomes disabled and switch to to the pan tool + useEffect(() => { + if (disabledTools.includes(selectedTool)) { + onToolChange("pan"); + } + }, [selectedTool, disabledTools, onToolChange]); + const divider = (