Skip to content

Commit 62d1b49

Browse files
committed
Sean 4/23 integrated MUITypes into redux and appStateSlice; created DirectChildMUI and DirectChildMUINestable components; added MUI components to DragDropPanel component; updated MUITypes; updated associated imports
> > Co-author-by: Heather Pfeiffer <[email protected]> Co-author-by: Jesse Wowczuk <[email protected]> Co-author-by: Zack Vandiver <[email protected]> Co-author-by: Sean Ryan <sfryan95>
1 parent 5523ba9 commit 62d1b49

File tree

12 files changed

+711
-181
lines changed

12 files changed

+711
-181
lines changed

app/src/components/left/DragDropPanel.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useDispatch, useSelector } from 'react-redux';
22
import Grid from '@mui/material/Grid';
33
import HTMLItem from './HTMLItem';
4-
import MUIItem from './MUI_Item';
4+
import MUIItem from './MUIItem';
55
import React from 'react';
66
import { RootState } from '../../redux/store';
77
import { deleteElement } from '../../redux/reducers/slice/appStateSlice';
@@ -46,11 +46,14 @@ const DragDropPanel = (props): JSX.Element => {
4646
(type) => type.name !== 'separator'
4747
);
4848

49-
const muiTypesToRender = state.MUITypes;
49+
const muiTypesToRender = state.MUITypes.filter(
50+
(type) => type.name !== 'separator'
51+
);
5052

5153
return (
5254
<div className={'HTMLItems'}>
5355
<div id="HTMLItemsTopHalf">
56+
{/* Root Components */}
5457
<Accordion className={classes.accordion}>
5558
<AccordionSummary
5659
expandIcon={<ExpandMoreIcon />}
@@ -64,6 +67,8 @@ const DragDropPanel = (props): JSX.Element => {
6467
<ComponentDrag isVisible={true} isThemeLight={props.isThemeLight} />
6568
</AccordionDetails>
6669
</Accordion>
70+
71+
{/* HTML Components */}
6772
<Accordion className={classes.accordion}>
6873
<AccordionSummary
6974
expandIcon={<ExpandMoreIcon />}
@@ -109,17 +114,15 @@ const DragDropPanel = (props): JSX.Element => {
109114
<AccordionDetails>
110115
<Grid container justifyContent="center">
111116
{muiTypesToRender.map((option) => {
112-
// if (option.name === 'MUI') {
113117
return (
114-
<HTMLItem
118+
<MUIItem
115119
name={option.name}
116120
key={`mui-${option.name}`}
117121
id={option.id}
118122
icon={option.icon}
119123
handleDelete={handleDelete}
120124
/>
121125
);
122-
// }
123126
})}
124127
</Grid>
125128
</AccordionDetails>

app/src/components/left/HTMLItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const useStyles = makeStyles({
1919
height: 'auto',
2020
width: 'auto',
2121
fontSize: 'small',
22+
alignItems: 'center',
2223
display: 'flex',
2324
flexDirection: 'row',
2425
justifyContent: 'space-evenly',

app/src/components/left/MUI_Item.tsx renamed to app/src/components/left/MUIItem.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const useStyles = makeStyles({
2020
MUIPanelItem: {
2121
height: 'auto',
2222
width: 'auto',
23-
fontSize: 'medium',
23+
fontSize: 'small',
2424
display: 'flex',
2525
flexDirection: 'row',
2626
justifyContent: 'space-evenly',
27+
alignItems: 'center',
2728
textAlign: 'center',
2829
cursor: 'grab'
2930
},
@@ -48,15 +49,20 @@ const MUIItem: React.FC<{
4849
// Use drag and drop functionality
4950
const classes = useStyles();
5051
const [modal, setModal] = useState(null);
52+
53+
const item = {
54+
type: ItemTypes.INSTANCE,
55+
newInstance: true,
56+
instanceType: 'MUI Component', // MUI Element? - we should carefully consider what we call this
57+
name,
58+
icon,
59+
instanceTypeId: id
60+
};
61+
62+
// console.log('draggable item', item);
63+
5164
const [{ isDragging }, drag] = useDrag({
52-
item: {
53-
type: ItemTypes.INSTANCE,
54-
newInstance: true,
55-
instanceType: 'MUI Component', // MUI Element? - we should carefully consider what we call this
56-
name,
57-
icon,
58-
instanceTypeId: id
59-
},
65+
item,
6066
collect: (monitor: any) => ({
6167
isDragging: !!monitor.isDragging()
6268
})
@@ -137,16 +143,16 @@ const MUIItem: React.FC<{
137143
// id over/under 20 logic
138144
// html-g{name} - html grid name = item
139145
return (
140-
<Grid item xs={5} key={`html-g${name}`} id="HTMLgrid">
141-
{id <= 20 && (
146+
<Grid item xs={5} key={`mui-g${name}`} id="HTMLgrid">
147+
{id >= 20 && (
142148
<div
143149
ref={drag}
144150
style={{
145151
backgroundColor: '#2D313A',
146152
backgroundImage: 'linear-gradient(160deg, #2D313A 0%, #1E2024 100%)'
147153
}}
148154
className={`${classes.MUIPanelItem} ${classes.darkThemeFontColor}`}
149-
id="HTMLItem"
155+
id="MUIItem"
150156
onClick={() => {
151157
handleClick();
152158
}}
@@ -158,12 +164,12 @@ const MUIItem: React.FC<{
158164
</div>
159165
)}
160166

161-
{id > 20 && (
167+
{id < 20 && (
162168
<div
163169
ref={drag}
164170
style={{ borderColor: '#C6C6C6' }}
165171
className={`${classes.MUIPanelItem} ${classes.darkThemeFontColor}`}
166-
id="HTMLItem"
172+
id="MUIItem"
167173
onClick={() => {
168174
handleClick();
169175
}}

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const Canvas = forwardRef<HTMLDivElement, CanvasProps>(({ zoom }, ref) => {
211211
}
212212
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
213213
if (item.newInstance && item.instanceType !== 'Component') {
214+
console.log('inside not component check', item);
214215
dispatch(
215216
//update state
216217
addChild({
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React from 'react';
2+
import { ChildElement, MUIType } from '../../interfaces/Interfaces';
3+
import { useDrag } from 'react-dnd';
4+
import { ItemTypes } from '../../constants/ItemTypes';
5+
import { combineStyles } from '../../helperFunctions/combineStyles';
6+
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
7+
import DeleteButton from './DeleteButton';
8+
import { useDispatch, useSelector } from 'react-redux';
9+
import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
10+
import { RootState } from '../../redux/store';
11+
import { emitEvent } from '../../helperFunctions/socket';
12+
13+
function DirectChildMUI({ childId, name, type, typeId, style }: ChildElement) {
14+
const state = useSelector((store: RootState) => store.appState);
15+
16+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
17+
18+
const dispatch = useDispatch();
19+
20+
// find the MUI element corresponding with this instance of an MUI element
21+
// find the current component to render on the canvas
22+
const MUIType: MUIType = state.MUITypes.find(
23+
(type: MUIType) => type.id === typeId
24+
);
25+
// hook that allows component to be draggable
26+
const [{ isDragging }, drag] = useDrag({
27+
// setting item attributes to be referenced when updating state with new instance of dragged item
28+
item: {
29+
type: ItemTypes.INSTANCE,
30+
newInstance: false,
31+
childId: childId,
32+
instanceType: type,
33+
instanceTypeId: typeId
34+
},
35+
collect: (monitor: any) => ({
36+
isDragging: !!monitor.isDragging()
37+
})
38+
});
39+
40+
const changeFocusFunction = (componentId: number, childId: number | null) => {
41+
dispatch(changeFocus({ componentId, childId }));
42+
if (roomCode) {
43+
emitEvent('changeFocusAction', roomCode, {
44+
componentId: componentId,
45+
childId: childId
46+
});
47+
// console.log('emit focus event from DirectChildMUI');
48+
}
49+
};
50+
51+
// onClickHandler is responsible for changing the focused component and child component
52+
function onClickHandler(event) {
53+
event.stopPropagation();
54+
changeFocusFunction(state.canvasFocus.componentId, childId);
55+
}
56+
57+
// combine all styles so that higher priority style specifications overrule lower priority style specifications
58+
// priority order is 1) style directly set for this child (style), 2) style of the referenced HTML element, and 3) default styling
59+
const interactiveStyle = {
60+
border:
61+
state.canvasFocus.childId === childId
62+
? '2px solid #0671e3'
63+
: '1px solid #31343A'
64+
};
65+
66+
const combinedStyle = combineStyles(
67+
combineStyles(combineStyles(globalDefaultStyle, MUIType.style), style),
68+
interactiveStyle
69+
);
70+
71+
return (
72+
<div
73+
onClick={onClickHandler}
74+
style={{ ...combinedStyle, backgroundColor: '#1E2024' }}
75+
ref={drag}
76+
id={`canv${childId}`}
77+
>
78+
<span>
79+
<strong style={{ color: 'white' }}>{MUIType.placeHolderShort}</strong>
80+
<DeleteButton
81+
id={childId}
82+
name={name[0].toLowerCase() + name.slice(1)}
83+
onClickHandler={onClickHandler}
84+
/>
85+
</span>
86+
</div>
87+
);
88+
}
89+
90+
export default DirectChildMUI;

0 commit comments

Comments
 (0)