Skip to content

Commit

Permalink
fix: avoid reselecting the tool if it's already selected
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Mar 22, 2024
1 parent 73f2750 commit 19f5857
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/component/hooks/useToolsFunctions.ts
Expand Up @@ -3,6 +3,7 @@ import lodashMap from 'lodash/map';
import { useCallback, useRef, useState } from 'react';
import { useToggleAccordion } from 'react-science/ui';

import { useChartData } from '../context/ChartContext';
import { useDispatch } from '../context/DispatchContext';
import { usePreferences } from '../context/PreferencesContext';
import { useToaster } from '../context/ToasterContext';
Expand All @@ -22,8 +23,16 @@ export default function useToolsFunctions() {
general: { invert },
},
} = usePreferences();
const {
toolOptions: { selectedTool: previousSelectedTool },
} = useChartData();
const handleChangeOption = useCallback(
(selectedTool) => {
//avoid reselecting the tool if it's already selected
if (selectedTool === previousSelectedTool) {
return;
}

if (
[
options.peakPicking.id,
Expand All @@ -47,7 +56,7 @@ export default function useToolsFunctions() {
payload: { selectedTool: selectedTool || options.zoom.id },
});
},
[dispatch, invert, openPanel, toaster],
[dispatch, invert, openPanel, previousSelectedTool, toaster],
);

const handleFullZoomOut = useCallback(() => {
Expand Down

0 comments on commit 19f5857

Please sign in to comment.