From ac4ca5b36488df54bef1636199d455b93dfa19ab Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 22 Jul 2021 15:24:35 +1000 Subject: [PATCH] Deselect when changing tools --- src/hooks/useMapSelection.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/hooks/useMapSelection.tsx b/src/hooks/useMapSelection.tsx index 515e00b..33e2abf 100644 --- a/src/hooks/useMapSelection.tsx +++ b/src/hooks/useMapSelection.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import SelectionMenu from "../components/selection/SelectionMenu"; import SelectTool from "../components/tools/SelectTool"; import { SelectionItemsChangeEventHandler } from "../types/Events"; @@ -22,9 +22,18 @@ function useMapSelection( setIsSelectionMenuOpen(open); } + const active = selectedToolId === "select"; + + useEffect(() => { + if (!active) { + setSelection(null); + setIsSelectionMenuOpen(false); + } + }, [active]); + const selectionTool = (