Skip to content

Commit

Permalink
Merge pull request #42 from concord-consortium/187369359-add-toolbar-…
Browse files Browse the repository at this point in the history
…toggle-off

feat: Allow toggling off a tool and return to select mode [PT-187369359]
  • Loading branch information
dougmartin authored Apr 5, 2024
2 parents b161142 + 8067a91 commit 5c9d878
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clsx } from "clsx";
import React, { useState } from "react";
import React, { useCallback, useState } from "react";

import SelectIcon from "../assets/select.svg";
import AddStateIcon from "../assets/add-state.svg";
Expand Down Expand Up @@ -79,16 +79,20 @@ export const ToolbarButton = ({tool, selectedTool, onClick}: ToolbarButtonProps)
export const Toolbar = ({tools, onToolSelected, onReset, onReturnToMainMenu}: ToolbarProps) => {
const [selectedTool, setSelectedTool] = useState<Tool>("select");

const handleToolSelected = (tool: Tool) => {
const handleToolSelected = useCallback((tool: Tool) => {
if (toggleableTools.includes(tool)) {
// allow toggling off a tool and returning to select mode
if (tool === selectedTool) {
tool = "select";
}
setSelectedTool(tool);
} else if (tool === "reset") {
onReset();
} else if (tool === "home") {
onReturnToMainMenu();
}
onToolSelected(tool);
};
}, [selectedTool, onReset, onReturnToMainMenu, onToolSelected]);

const topTools = tools.filter(tool => !nonTopTools.includes(tool));
const bottomTools = tools.filter(tool => nonTopTools.includes(tool));
Expand Down

0 comments on commit 5c9d878

Please sign in to comment.