Skip to content

Commit d00b60f

Browse files
committed
click to add functionality added to collab room
1 parent a2a134f commit d00b60f

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

app/src/components/left/HTMLItem.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { useDrag } from 'react-dnd';
1212
import { IconProps } from '@mui/material';
1313
import CodeIcon from '@mui/icons-material/Code';
1414
import * as Icons from '@mui/icons-material';
15-
import { useDispatch } from 'react-redux';
15+
import { useDispatch, useSelector } from 'react-redux';
1616
import { addChild } from '../../redux/reducers/slice/appStateSlice';
17+
import { emitEvent } from '../../helperFunctions/socket';
1718

1819
const useStyles = makeStyles({
1920
HTMLPanelItem: {
@@ -43,6 +44,8 @@ const HTMLItem: React.FC<{
4344
//load mui icons base on string parameter
4445
const IconComponent = Icons[icon];
4546

47+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode); // current roomCode
48+
4649
const classes = useStyles();
4750

4851
const [modal, setModal] = useState(null);
@@ -123,7 +126,7 @@ const HTMLItem: React.FC<{
123126

124127
const dispatch = useDispatch();
125128

126-
const handleClick = () => {
129+
/* const handleClick = () => {
127130
console.log('Component clicked:', name);
128131
console.log('id', id);
129132
// Dispatch action to add child
@@ -137,6 +140,25 @@ const HTMLItem: React.FC<{
137140
}
138141
})
139142
);
143+
};*/
144+
145+
const handleClick = () => {
146+
console.log('Component clicked:', name);
147+
console.log('id', id);
148+
const childData = {
149+
type: 'HTML Element',
150+
typeId: id,
151+
childId: null,
152+
contextParam: {
153+
allContext: []
154+
}
155+
};
156+
157+
dispatch(addChild(childData));
158+
if (roomCode) {
159+
// Emit 'addChildAction' event to the server
160+
emitEvent('addChildAction', roomCode, childData);
161+
}
140162
};
141163

142164
// updated the id's to reflect the new element types input and label

0 commit comments

Comments
 (0)