Skip to content

Commit 9d94bf2

Browse files
committed
#417 committing job and moving to laptop
1 parent e484938 commit 9d94bf2

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

webapp/components/general/ControlPanelTreeItem.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import Visibility from '@material-ui/icons/Visibility';
99
import ColorLens from '@material-ui/icons/ColorLens';
1010
import Shuffle from '@material-ui/icons/Shuffle';
1111
import { ChromePicker } from 'react-color';
12+
import { useDispatch, useSelector } from 'react-redux';
1213
import { experimentLabelColor } from '../../theme';
14+
import { changeInstanceColor } from '../../redux/actions/general';
1315

1416
const useStyles = makeStyles((theme) => ({
1517
networkItem: {
@@ -35,14 +37,26 @@ const useStyles = makeStyles((theme) => ({
3537

3638
const ControlPanelTreeItem = (props) => {
3739
const classes = useStyles();
40+
const dispatch = useDispatch();
3841
const [showColorPicker, setShowColorPicker] = React.useState(false);
3942
const [isHoveredOver, setIsHoveredOver] = React.useState(false);
4043
const [color, setColor] = React.useState('#ff0000');
44+
const instances = useSelector((state) => state.general.instances);
4145

4246
const handleColorSelection = (color, event, nodeId) => {
47+
const newInstances = instances.filter((instance) => !(instance.instancePath.startsWith(nodeId)));
48+
newInstances.push({
49+
instancePath: nodeId,
50+
color: {
51+
r: color.rgb.r / 255,
52+
g: color.rgb.g / 255,
53+
b: color.rgb.b / 255,
54+
a: color.rgb.a,
55+
},
56+
});
57+
dispatch(changeInstanceColor(newInstances));
58+
console.log(color);
4359
setColor(color.hex);
44-
event.preventDefault();
45-
event.stopPropagation();
4660
};
4761

4862
const generateRandomColor = () => {

0 commit comments

Comments
 (0)