Skip to content

Commit bd83597

Browse files
committed
fix small bugs
1 parent 4837abd commit bd83597

File tree

6 files changed

+22
-32
lines changed

6 files changed

+22
-32
lines changed

app/src/components/ContextAPIManager/CreateTab/components/AddContextForm.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const AddContextForm = ({
2323
const handleClick = () => {
2424
if (contextInput === '' || contextInput === null) return;
2525
handleClickSelectContext();
26-
27-
//need to trigger the generate code functionality to update the code preview tab. Sending dummy data to trigger with a DELELTE ELEMENT dispatch method
28-
dispatch({
29-
type: 'DELETE ELEMENT',
30-
payload: 'FAKE_ID'
31-
});
3226
};
3327

3428
const onChange = (event, newValue) => {

app/src/components/bottom/UseStateModal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState, useContext} from 'react';
1+
import React, {useState, useContext, useRef} from 'react';
22
import Modal from '@material-ui/core/Modal';
33
import StateContext from '../../context/context';
44
import TableStateProps from './TableStateProps';
@@ -10,7 +10,7 @@ function UseStateModal({ updateAttributeWithState, attributeToChange, childId })
1010
const [stateKey, setStateKey] = useState('');
1111
const [statePropsId, setStatePropsId] = useState(-1);
1212
const [componentProviderId, setComponentProviderId] = useState(1);
13-
13+
const container = useRef(null);
1414
// table to choose state from
1515
const body = (
1616
<div className="useState-position">
@@ -46,9 +46,9 @@ function UseStateModal({ updateAttributeWithState, attributeToChange, childId })
4646
);
4747

4848
return (
49-
<div>
49+
<div ref={container}>
5050
<button className="useState-btn" onClick={() => setOpen(true)}>USE STATE</button>
51-
<Modal open={open}>{body}</Modal>
51+
<Modal open={open} container={container.current}>{body}</Modal>
5252
</div>
5353
);
5454
}

app/src/components/main/DemoRender.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const DemoRender = (): JSX.Element => {
5858
//Switch between components when clicking on a link in the live render
5959
window.onmessage = (event) => {
6060
if (event.data === undefined) return;
61-
// console.log('event: ', event);
6261
const component: string = event.data?.split('/').at(-1);
6362
const componentId =
6463
component &&

app/src/containers/CustomizationPanel.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
5454
const [eventRow, setEventRow] = useState([]);
5555
// ------------------------------------------- added code above -------------------------------------------
5656
const currFocus = getFocus().child;
57-
// state.components
58-
// .find((el) => {
59-
// return el.id === state.canvasFocus.componentId;
60-
// })
61-
// .children.find((el) => {
62-
// return el.childId === state.canvasFocus.childId;
63-
// });
57+
6458
useEffect( () => {
6559
currFocus?.attributes?.compLink && setCompLink(currFocus.attributes.compLink);
6660
setEventAll(['', '']);

app/src/helperFunctions/generateCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ const generateUnformattedCode = (
410410
// ------------------------------------------- added code above -------------------------------------------
411411
let generatedCode = "import React, { useState, useEffect, useContext} from 'react';\n\n";
412412
generatedCode += currComponent.name === 'APP' ? contextImports : '';
413-
generatedCode += importReactRouter ? `import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';` : ``;
413+
generatedCode += importReactRouter ? `import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';\n` : ``;
414414
generatedCode += createContextImport() ? `${createContextImport()}\n`: '';
415415
generatedCode += importsMapped ? `${importsMapped}\n` : '';
416416
// below is the return statement of the codepreview

app/src/reducers/componentReducer.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,25 @@ const reducer = (state: State, action: Action) => {
8585
// update all ids and typeIds to match one another
8686
const updateAllIds = (comp: Component[] | ChildElement[]) => {
8787
// put components' names and ids into an obj
88-
const obj = {};
89-
comp.forEach((el) => {
90-
obj[el.name] = el.id;
91-
});
88+
const obj = { spr: 1000, others: 1 };
89+
// comp.forEach((el) => {
90+
// if (!obj[el.name]) obj[el.name] = el.id;
91+
// });
9292
// for each of the components, if it has children, iterate through that children array
9393
comp.forEach((el) => {
9494
if (el.children.length > 0) {
9595
for (let i = 0; i < el.children.length; i++) {
9696
// update each child's childId
97-
el.children[i].childId = i + 1;
98-
// if the child's name and id exists in the object
99-
if (obj[el.children[i].name]) {
100-
// set the child's typeId to be the value in the object of the child's name key
101-
el.children[i].typeId = obj[el.children[i].name];
97+
if (el.children[i].name === 'separator') {
98+
el.children[i].childId = obj['spr']++;
99+
} else {
100+
el.children[i].childId = obj['others']++;
102101
}
102+
// // if the child's name and id exists in the object
103+
// if (obj[el.children[i].name]) {
104+
// // set the child's typeId to be the value in the object of the child's name key
105+
// el.children[i].typeId = obj[el.children[i].name];
106+
// }
103107
// recursively call the updateAllIds function on the child's children array if
104108
// the child's children array is greater than 0
105109
if (el.children[i].children.length > 0) {
@@ -145,7 +149,7 @@ const reducer = (state: State, action: Action) => {
145149
// component has a children array, iterate through the array of children
146150
child.forEach((el) => {
147151
if (el.children.length) {
148-
const arr = [];
152+
const arr: ChildElement[] = [];
149153
for (let i = 0; i < el.children.length; i++) {
150154
// check to see if the name variable doesn't match the name of the child
151155
if (el.children[i].name !== name) {
@@ -510,7 +514,6 @@ const reducer = (state: State, action: Action) => {
510514
);
511515
return { ...state, components };
512516
}
513-
// ------------------------------------------- added code below -------------------------------------------
514517
case 'UPDATE EVENTS': {
515518
const { events } = action.payload;
516519
if (JSON.stringify(events) === '{}') return state;
@@ -552,8 +555,6 @@ const reducer = (state: State, action: Action) => {
552555
);
553556
return { ...state, components };
554557
}
555-
// ------------------------------------------- added code above -------------------------------------------
556-
557558
case 'DELETE CHILD': {
558559
// if in-focus instance is a top-level component and not a child, don't delete anything
559560
if (!state.canvasFocus.childId) return state;
@@ -752,6 +753,7 @@ const reducer = (state: State, action: Action) => {
752753
});
753754
const components: Component[] = deleteById(action.payload, name);
754755
const rootComponents: number[] = updateRoots(components);
756+
const canvasFocus = { ...state.canvasFocus, childId: null };
755757
components.forEach((el, i) => {
756758
el.code = generateCode(
757759
components,
@@ -763,6 +765,7 @@ const reducer = (state: State, action: Action) => {
763765
});
764766
return {
765767
...state,
768+
canvasFocus,
766769
HTMLTypes
767770
};
768771
}

0 commit comments

Comments
 (0)