@@ -5,20 +5,24 @@ import AddCircleIcon from '@mui/icons-material/AddCircle';
5
5
import ComponentDrag from './ComponentDrag' ;
6
6
import ComponentPanel from '../right/ComponentPanel' ;
7
7
import { RootState } from '../../redux/store' ;
8
- import { useSelector } from 'react-redux' ;
8
+ import { useSelector , useDispatch } from 'react-redux' ;
9
9
import ComponentsContainer from './ComponentsContainer' ;
10
10
import CreatePanel from './CreatePanel' ;
11
11
import HeaderButton from './HeaderButton' ;
12
+ import HTMLItem from './HtmlItem' ;
13
+ import Grid from '@mui/material/Grid' ;
14
+ import HTMLTypes from './redux/HTMLTypes' ;
12
15
13
16
interface ModulePanelProps {
14
17
isThemeLight : boolean ;
15
18
}
16
- const ModulePanel : React . FC < ModulePanelProps > = ( {
17
- isThemeLight
18
- } : ModulePanelProps ) => {
19
+ const ModulePanel : React . FC < ModulePanelProps > = ( { isThemeLight } ) => {
19
20
const state = useSelector ( ( store : RootState ) => store . appState ) ;
21
+ const contextParam = useSelector ( ( store : RootState ) => store . contextSlice ) ;
22
+ const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ;
20
23
const [ isCreatingModule , setIsCreatingModule ] = useState ( false ) ;
21
24
const [ isEditingModule , setIsEditingModule ] = useState ( false ) ;
25
+ const dispatch = useDispatch ( ) ;
22
26
23
27
const customComponents = state . components . filter (
24
28
( comp ) => ! state . rootComponents . includes ( comp . id )
@@ -32,6 +36,20 @@ const ModulePanel: React.FC<ModulePanelProps> = ({
32
36
setIsEditingModule ( ! isEditingModule ) ;
33
37
} ;
34
38
39
+ const handleDelete = ( id : number ) : void => {
40
+ dispatch ( deleteElement ( { id : id , contextParam : contextParam } ) ) ;
41
+ if ( roomCode ) {
42
+ emitEvent ( 'deleteElementAction' , roomCode , {
43
+ id,
44
+ contextParam
45
+ } ) ;
46
+ }
47
+ } ;
48
+
49
+ const htmlTypesToRender = state . HTMLTypes . filter (
50
+ ( type ) => type . name !== 'separator'
51
+ ) ;
52
+
35
53
return (
36
54
< div className = "modulePanelContainer" >
37
55
{ isEditingModule ? (
@@ -49,6 +67,26 @@ const ModulePanel: React.FC<ModulePanelProps> = ({
49
67
setIsCreatingModule = { setIsCreatingModule }
50
68
isThemeLight = { false }
51
69
/>
70
+ < Grid container justifyContent = "space-around" columnSpacing = { 2 } >
71
+ { htmlTypesToRender . map ( ( option ) => {
72
+ if (
73
+ ( option . name === 'Switch' ||
74
+ option . name === 'LinkTo' ||
75
+ option . name === 'Route' ) &&
76
+ state . projectType === 'Classic React'
77
+ ) {
78
+ return (
79
+ < HTMLItem
80
+ name = { option . name }
81
+ key = { `html-${ option . name } ` }
82
+ id = { option . id }
83
+ icon = { option . icon }
84
+ handleDelete = { handleDelete }
85
+ />
86
+ ) ;
87
+ }
88
+ } ) }
89
+ </ Grid >
52
90
< ComponentDrag
53
91
isVisible = { true }
54
92
isThemeLight = { false }
0 commit comments