Skip to content

Commit

Permalink
debounce color selection
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Nov 1, 2023
1 parent f615096 commit 18bb022
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"react-waypoint": "^9.0.3",
"redux": "4.2.0",
"redux-logic": "^3.0.3",
"reselect": "4.0.0"
"reselect": "4.0.0",
"use-debounce": "^9.0.4"
},
"resolutions": {
"react": "^16",
Expand Down
10 changes: 6 additions & 4 deletions src/components/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { connect } from "react-redux";
import { Popover, Tooltip } from "antd";
import { HexColorInput, HexColorPicker } from "react-colorful";
import classNames from "classnames";
import { useDebounce } from "use-debounce";

import selectionStateBranch from "../../state/selection";
import { AGENT_COLORS } from "../../containers/ViewerPanel/constants";
Expand Down Expand Up @@ -37,19 +38,20 @@ const ColorPicker = ({
setRecentColors,
}: ColorPickerProps) => {
const [color, setColor] = useState(initialColor);
const [debouncedColor] = useDebounce(color, 250);

const handleColorChange = (color: string) => {

Check warning on line 43 in src/components/ColorPicker/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

'color' is defined but never used
const colorChanges: ColorChangesMap = {
agents: { [agentName]: tags },
color: color,
color: debouncedColor,
};
setColorChanges(colorChanges);
updateRecentColors(color);
updateRecentColors(debouncedColor);
};

useEffect(() => {
handleColorChange(color);
}, [color]);
handleColorChange(debouncedColor);
}, [debouncedColor]);

const updateRecentColors = (color: string) => {
if (recentColors.includes(color)) {
Expand Down

0 comments on commit 18bb022

Please sign in to comment.