|
| 1 | +import { useDispatch, useSelector } from 'react-redux'; |
| 2 | +import Grid from '@mui/material/Grid'; |
| 3 | +import MUIItem from './MUIItem'; |
| 4 | +import React from 'react'; |
| 5 | +import { RootState } from '../../redux/store'; |
| 6 | +import { deleteElement } from '../../redux/reducers/slice/appStateSlice'; |
| 7 | +import { emitEvent } from '../../helperFunctions/socket'; |
| 8 | +import Accordion from '@mui/material/Accordion'; |
| 9 | +import AccordionSummary from '@mui/material/AccordionSummary'; |
| 10 | +import AccordionDetails from '@mui/material/AccordionDetails'; |
| 11 | +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; |
| 12 | +import { makeStyles } from '@mui/styles'; |
| 13 | +import ComponentDrag from './ComponentDrag'; |
| 14 | + |
| 15 | +const useStyles = makeStyles({ |
| 16 | + accordion: { |
| 17 | + backgroundColor: '#000000', // Set the background color to gray |
| 18 | + color: '#ffffff' // Set the text color to white |
| 19 | + }, |
| 20 | + accordionSummary: { |
| 21 | + backgroundColor: '#000000', // Set the background color of the summary to gray |
| 22 | + color: '#ffffff' // Set the text color of the summary to white |
| 23 | + } |
| 24 | +}); |
| 25 | + |
| 26 | +const MUIDragDropPanel = (props): JSX.Element => { |
| 27 | + const classes = useStyles(); |
| 28 | + const dispatch = useDispatch(); |
| 29 | + |
| 30 | + const state = useSelector((store: RootState) => store.appState); |
| 31 | + const contextParam = useSelector((store: RootState) => store.contextSlice); |
| 32 | + const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode); |
| 33 | + |
| 34 | + const handleDelete = (id: number): void => { |
| 35 | + dispatch(deleteElement({ id: id, contextParam: contextParam })); |
| 36 | + if (roomCode) { |
| 37 | + emitEvent('deleteElementAction', roomCode, { |
| 38 | + id, |
| 39 | + contextParam |
| 40 | + }); |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + const htmlTypesToRender = state.HTMLTypes.filter( |
| 45 | + (type) => type.name !== 'separator' |
| 46 | + ); |
| 47 | + |
| 48 | + const muiTypesToRender = state.MUITypes.filter( |
| 49 | + (type) => type.name !== 'separator' |
| 50 | + ); |
| 51 | + |
| 52 | + return ( |
| 53 | + <div className={'HTMLItems'}> |
| 54 | + <div id="HTMLItemsTopHalf"> |
| 55 | + {/* Root Components */} |
| 56 | + <Accordion className={classes.accordion}> |
| 57 | + <AccordionSummary |
| 58 | + expandIcon={<ExpandMoreIcon />} |
| 59 | + aria-controls="panel1a-content" |
| 60 | + id="panel1a-header" |
| 61 | + className={classes.accordionSummary} |
| 62 | + > |
| 63 | + <h3>Root Components</h3> |
| 64 | + </AccordionSummary> |
| 65 | + <AccordionDetails> |
| 66 | + <ComponentDrag isVisible={true} isThemeLight={props.isThemeLight} /> |
| 67 | + </AccordionDetails> |
| 68 | + </Accordion> |
| 69 | + |
| 70 | + {/* MUI Components */} |
| 71 | + <Accordion className={classes.accordion}> |
| 72 | + <AccordionSummary |
| 73 | + expandIcon={<ExpandMoreIcon />} |
| 74 | + aria-controls="panel2a-content" |
| 75 | + id="panel2a-header" |
| 76 | + className={classes.accordionSummary} |
| 77 | + > |
| 78 | + <h3>MUI Components</h3> |
| 79 | + </AccordionSummary> |
| 80 | + <AccordionDetails> |
| 81 | + <Grid container justifyContent="center"> |
| 82 | + {muiTypesToRender.map((option) => { |
| 83 | + return ( |
| 84 | + <MUIItem |
| 85 | + name={option.name} |
| 86 | + key={`mui-${option.name}`} |
| 87 | + id={option.id} |
| 88 | + icon={option.icon} |
| 89 | + handleDelete={handleDelete} |
| 90 | + /> |
| 91 | + ); |
| 92 | + })} |
| 93 | + </Grid> |
| 94 | + </AccordionDetails> |
| 95 | + </Accordion> |
| 96 | + |
| 97 | + {/* Next.js */} |
| 98 | + {state.projectType === 'Next.js' ? ( |
| 99 | + <h3 style={{ color: 'C6C6C6' }}>Next.js</h3> |
| 100 | + ) : null} |
| 101 | + {htmlTypesToRender.map((option) => { |
| 102 | + if ( |
| 103 | + option.framework === 'nextjs' && |
| 104 | + state.projectType === 'Next.js' |
| 105 | + ) { |
| 106 | + return ( |
| 107 | + <HTMLItem |
| 108 | + name={option.name} |
| 109 | + key={`html-${option.name}`} |
| 110 | + id={option.id} |
| 111 | + icon={option.icon} |
| 112 | + handleDelete={handleDelete} |
| 113 | + /> |
| 114 | + ); |
| 115 | + } |
| 116 | + })} |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + ); |
| 120 | +}; |
| 121 | + |
| 122 | +export default MUIDragDropPanel; |
0 commit comments