@@ -12,8 +12,9 @@ import { useDrag } from 'react-dnd';
12
12
import { IconProps } from '@mui/material' ;
13
13
import CodeIcon from '@mui/icons-material/Code' ;
14
14
import * as Icons from '@mui/icons-material' ;
15
- import { useDispatch } from 'react-redux' ;
15
+ import { useDispatch , useSelector } from 'react-redux' ;
16
16
import { addChild } from '../../redux/reducers/slice/appStateSlice' ;
17
+ import { emitEvent } from '../../helperFunctions/socket' ;
17
18
18
19
const useStyles = makeStyles ( {
19
20
HTMLPanelItem : {
@@ -43,6 +44,8 @@ const HTMLItem: React.FC<{
43
44
//load mui icons base on string parameter
44
45
const IconComponent = Icons [ icon ] ;
45
46
47
+ const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ; // current roomCode
48
+
46
49
const classes = useStyles ( ) ;
47
50
48
51
const [ modal , setModal ] = useState ( null ) ;
@@ -123,7 +126,7 @@ const HTMLItem: React.FC<{
123
126
124
127
const dispatch = useDispatch ( ) ;
125
128
126
- const handleClick = ( ) => {
129
+ /* const handleClick = () => {
127
130
console.log('Component clicked:', name);
128
131
console.log('id', id);
129
132
// Dispatch action to add child
@@ -137,6 +140,25 @@ const HTMLItem: React.FC<{
137
140
}
138
141
})
139
142
);
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
+ }
140
162
} ;
141
163
142
164
// updated the id's to reflect the new element types input and label
0 commit comments