Skip to content

Commit 34203b7

Browse files
committed
deleted keyBindCreateComponent & its useEffect hook in ComponentPanel.tsx because it was duplicating handleCreateElement, currently dealing with bug in custom elements list that makes the MUI add more to the render rather than toggling
1 parent 6001f5a commit 34203b7

File tree

9 files changed

+43
-57
lines changed

9 files changed

+43
-57
lines changed

app/src/components/ContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function ContextMenu({
8484

8585
// remove the keystroke listener on unmount.
8686
useEffect(
87-
// the next line is intentional, im not an idiot, do not remove.
87+
// the next line is intentional
8888
() => () => {
8989
document.removeEventListener('keydown', keyStrokeFunction); // remove old one first if we have
9090
},

app/src/components/bottom/CreationPanel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable max-len */
22
import React from 'react';
3-
import ComponentPanel from '../right/ComponentPanel';
43
import HTMLPanel from '../left/HTMLPanel';
54
import { useSelector } from 'react-redux';
65
import { RootState } from '../../redux/store';
@@ -23,7 +22,7 @@ const CreationPanel = (props): JSX.Element => {
2322
const style = useSelector((store: RootState) => store.styleSlice);
2423
return (
2524
<div className="creation-panel" style={style.style}>
26-
{/* NOTE: This component has been moved to ModulePanel.tsx
25+
{/* NOTE: This component has been moved to ModulePanel.tsx
2726
<ComponentPanel isThemeLight={props.isThemeLight} /> */}
2827
<HTMLPanel isThemeLight={props.isThemeLight} />
2928
</div>

app/src/components/left/CreatePanel.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ const CreatePanel = (props): JSX.Element => {
201201
textAlign: 'center',
202202
marginBottom: '6px'
203203
}}
204+
key={name + idx}
204205
>
205206
<Button component="label" id={name + '-button'} key={name + idx}>
206207
{name}
@@ -225,7 +226,7 @@ const CreatePanel = (props): JSX.Element => {
225226
aria-label="Custom Elements"
226227
id="customElements"
227228
key="customElements-header"
228-
textAlign="center"
229+
sx={{ textAlign: 'center' }}
229230
>
230231
Custom Elements
231232
</Button>
@@ -254,12 +255,11 @@ const CreatePanel = (props): JSX.Element => {
254255
inputProps={{ 'aria-label': 'HTML + MUI switch' }}
255256
sx={{ margin: '0 10px' }} // Adjust spacing between text and switch
256257
/>
257-
<p className="smallerText">
258-
<HeaderButton
259-
headerName="HTML + MUI"
260-
infoText="Material UI (or MUI) is a customizable library of React components. Toggle this switch on to see both HTML elements and MUI components that you can drag onto your canvas. For more about MUI, see https://mui.com for more details."
261-
/>
262-
</p>
258+
259+
<HeaderButton
260+
headerName="HTML + MUI"
261+
infoText="Material UI (or MUI) is a customizable library of React components. Toggle this switch on to see both HTML elements and MUI components that you can drag onto your canvas. For more about MUI, ee https://mui.com for more details."
262+
/>
263263
</Box>
264264
</FormGroup>
265265
{MUIMode

app/src/components/left/HTMLPanel.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ const HTMLPanel = (props): JSX.Element => {
9898
style: {},
9999
placeHolderShort: name,
100100
placeHolderLong: '',
101-
icon: null
101+
icon: null,
102+
nestable: true
102103
};
103104

104105
dispatch(addElement(newElement));
@@ -118,7 +119,6 @@ const HTMLPanel = (props): JSX.Element => {
118119

119120
const handleSubmit = (e) => {
120121
e.preventDefault();
121-
console.log('did submit');
122122
if (tag.trim() === '' || name.trim() === '') return triggerError('empty');
123123
if (!tag.charAt(0).match(/[a-zA-Z]/) || !name.charAt(0).match(/[a-zA-Z]/))
124124
return triggerError('letters');
@@ -216,11 +216,11 @@ const HTMLPanel = (props): JSX.Element => {
216216
<HelpIcon id={id} size="small" />
217217
</div>
218218
<div>
219-
Each HTML element created will become part of the DOM, the
220-
document model for displaying the page in the browser. The tag
221-
will begin or end the element in source code. For example, you
222-
could create an HTML element named 'paragraph' and it will
223-
appear in its tag 'p' in your HTML markup -- as {`<p> </p>`}.
219+
Each custom HTML element you create can be added using
220+
drag-and-drop to the DOM. Its HTML tag will begin or end the
221+
element in source code. For example, you could create an element
222+
named 'navigation' and use the tag 'nav' in your HTML markup so
223+
that it appears as {`<nav> </nav>`}.
224224
</div>
225225
</div>
226226
</Popover>
@@ -263,7 +263,7 @@ const HTMLPanel = (props): JSX.Element => {
263263
severity="success"
264264
sx={{ width: '100%', color: 'white', backgroundColor: '#f88e16' }}
265265
>
266-
HTML Tag Created!
266+
HTML Element Created!
267267
</Alert>
268268
</Snackbar>
269269
</>

app/src/components/left/ModulePanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ModulePanel: React.FC<ModulePanelProps> = ({ isThemeLight }) => {
6060
textAlign: 'center'
6161
}}
6262
>
63-
<CreatePanel />
63+
<CreatePanel key="createPanel2" />
6464
</div>
6565
) : (
6666
<div

app/src/components/right/ComponentPanel.tsx

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,25 @@ const ComponentPanel = ({ setIsCreatingModule, isThemeLight }): JSX.Element => {
6363
}
6464
};
6565

66-
const handleCreateElement = useCallback((e) => {
67-
if (
68-
e.key === 'Enter' &&
69-
e.target.tagName === 'INPUT' &&
70-
e.target.type !== 'checkbox' &&
71-
e.target.id !== 'filled-hidden-label-small'
72-
) {
73-
e.preventDefault();
74-
document.getElementById('submitButton').click();
75-
}
76-
}, []);
66+
// const handleCreateElement = useCallback((e) => {
67+
// if (
68+
// e.key === 'Enter' &&
69+
// e.target.tagName === 'INPUT' &&
70+
// e.target.type !== 'checkbox' &&
71+
// e.target.id !== 'filled-hidden-label-small'
72+
// ) {
73+
// e.preventDefault();
74+
// document.getElementById('submitButton').click();
75+
// }
76+
// }, []);
7777

78-
useEffect(() => {
79-
document.addEventListener('keydown', handleCreateElement);
80-
return () => {
81-
document.removeEventListener('keydown', handleCreateElement);
82-
};
83-
}, []);
78+
// useEffect(() => {
79+
// document.addEventListener('keydown', handleCreateElement);
80+
// console.log('what event', event);
81+
// return () => {
82+
// document.removeEventListener('keydown', handleCreateElement);
83+
// };
84+
// }, []);
8485

8586
const handleNameInput = (e: React.ChangeEvent<HTMLInputElement>) => {
8687
setErrorStatus(false);
@@ -155,24 +156,6 @@ const ComponentPanel = ({ setIsCreatingModule, isThemeLight }): JSX.Element => {
155156
triggerError(error);
156157
};
157158

158-
const keyBindCreateComponent = useCallback((e) => {
159-
if (
160-
e.key === 'Enter' &&
161-
e.target.tagName === 'INPUT' &&
162-
e.target.type !== 'checkbox'
163-
) {
164-
e.preventDefault();
165-
document.getElementById('addComponentButton').click();
166-
}
167-
}, []);
168-
169-
useEffect(() => {
170-
document.addEventListener('keydown', keyBindCreateComponent);
171-
return () => {
172-
document.removeEventListener('keydown', keyBindCreateComponent);
173-
};
174-
}, []);
175-
176159
const handleAlertClose = (
177160
event: React.SyntheticEvent | Event,
178161
reason?: string
@@ -204,6 +187,12 @@ const ComponentPanel = ({ setIsCreatingModule, isThemeLight }): JSX.Element => {
204187
error={errorStatus}
205188
helperText={errorStatus ? errorMsg : ''}
206189
onChange={handleNameInput}
190+
// onKeyDown={(e) => {
191+
// if (e.key === 'Enter') {
192+
// e.preventDefault();
193+
// handleNameSubmit;
194+
// }
195+
// }}
207196
size="small"
208197
sx={{ width: '80%' }}
209198
/>

app/src/containers/MainContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const MainContainer = (props): JSX.Element => {
4242
const id: string = useSelector((store: RootState) => store.appState._id);
4343

4444
const appState = useSelector((store: RootState) => store.appState);
45-
console.log(appState.canvasFocus);
4645

4746
// const { style } = useSelector((store: RootState) => ({
4847
// style: store.styleSlice
@@ -100,7 +99,6 @@ const MainContainer = (props): JSX.Element => {
10099
// use effect for contextMenu listeners
101100
useEffect(() => {
102101
document.addEventListener('contextmenu', (e) => {
103-
console.log(e.target);
104102
if (
105103
ContextMenuRef.current != null &&
106104
ContextMenuRef.current.contains(e.target)

app/src/helperFunctions/generateCode.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ const generateUnformattedCode = (
121121

122122
currentComponent.children.forEach((child) => {
123123
const newChild = { ...child };
124-
console.log({ newChild });
125124
switch (child.type) {
126125
case 'Component':
127126
const component = components.find((c) => c.id === child.typeId);

app/src/redux/reducers/slice/appStateSlice.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ const appStateSlice = createSlice({
268268
useStateCodes: [],
269269
passedInProps: []
270270
};
271+
271272
state.components.push(newComponent);
272273
// functionality if the new component will become the root component
273274
if (action.payload.root) state.rootComponents.push(newComponent.id);

0 commit comments

Comments
 (0)