Skip to content

Commit 49ec461

Browse files
committed
User can now click to add elements to canvas
1 parent 193d965 commit 49ec461

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

app/src/components/left/HTMLItem.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ 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';
16+
import { addChild } from '../../redux/reducers/slice/appStateSlice';
1517

1618
const useStyles = makeStyles({
1719
HTMLPanelItem: {
@@ -118,6 +120,25 @@ const HTMLItem: React.FC<{
118120
})
119121
);
120122
};
123+
124+
const dispatch = useDispatch();
125+
126+
const handleClick = () => {
127+
console.log('Component clicked:', name);
128+
console.log('id', id);
129+
// Dispatch action to add child
130+
dispatch(
131+
addChild({
132+
type: 'HTML Element',
133+
typeId: id,
134+
childId: null,
135+
contextParam: {
136+
allContext: []
137+
}
138+
})
139+
);
140+
};
141+
121142
// updated the id's to reflect the new element types input and label
122143
return (
123144
// HTML Elements
@@ -128,6 +149,9 @@ const HTMLItem: React.FC<{
128149
style={{ borderColor: '#C6C6C6' }}
129150
className={`${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`}
130151
id="HTMLItem"
152+
onClick={() => {
153+
handleClick();
154+
}}
131155
>
132156
{typeof IconComponent !== 'undefined' && (
133157
<IconComponent fontSize="small" align-items="center" />
@@ -143,17 +167,21 @@ const HTMLItem: React.FC<{
143167
style={{ borderColor: '#C6C6C6' }}
144168
className={`${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`}
145169
id="HTMLItem"
170+
onClick={() => {
171+
handleClick();
172+
}}
146173
>
147174
{typeof CodeIcon !== 'undefined' && (
148-
<CodeIcon fontSize="small" align-items="center" />)}
175+
<CodeIcon fontSize="small" align-items="center" />
176+
)}
149177
{name}
150-
<button
178+
<button
151179
id="newElement"
152180
style={{ color: '#C6C6C6' }}
153181
onClick={() => deleteAllInstances(id)}
154-
>
155-
X
156-
</button>
182+
>
183+
X
184+
</button>
157185
</div>
158186
)}
159187
{modal}

0 commit comments

Comments
 (0)