Skip to content

Commit 52925c8

Browse files
committed
generate code works with custom elements
1 parent a5fd115 commit 52925c8

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

app/src/components/main/DirectChildHTML.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ItemTypes } from '../../constants/ItemTypes';
1010
import { stateContext } from '../../context/context';
1111
import { combineStyles } from '../../helperFunctions/combineStyles';
1212
import IndirectChild from './IndirectChild';
13-
import HTMLTypes from '../../context/HTMLTypes';
1413
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
1514

1615
function DirectChildHTML({
@@ -24,7 +23,7 @@ function DirectChildHTML({
2423

2524
// find the HTML element corresponding with this instance of an HTML element
2625
// find the current component to render on the canvas
27-
const HTMLType: HTMLType = HTMLTypes.find(
26+
const HTMLType: HTMLType = state.HTMLTypes.find(
2827
(type: HTMLType) => type.id === typeId
2928
);
3029

app/src/containers/RightContainer.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import TextField from '@material-ui/core/TextField';
88
import Button from '@material-ui/core/Button';
99

1010
import { stateContext } from '../context/context';
11-
import HTMLTypes from '../context/HTMLTypes';
1211

1312
import ProjectManager from '../components/right/ProjectManager';
1413

@@ -116,7 +115,7 @@ const RightContainer = (props): JSX.Element => {
116115
// if type is HTML Element, search through HTML types to find matching element's name
117116
} else if (focusChild.type === 'HTML Element') {
118117
focusTarget.child.type = 'HTML element';
119-
focusTarget.child.name = HTMLTypes.find(
118+
focusTarget.child.name = state.HTMLTypes.find(
120119
elem => elem.id === focusChild.typeId
121120
).name;
122121
}
@@ -166,7 +165,7 @@ const RightContainer = (props): JSX.Element => {
166165
const handlePageDelete = (id) => () => {
167166
dispatch({ type: 'DELETE PAGE', payload: { id }});
168167
}
169-
168+
170169
const handleDeleteReusableComponent = () => {
171170
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
172171
}
@@ -398,7 +397,7 @@ const RightContainer = (props): JSX.Element => {
398397
DELETE PAGE
399398
</Button>
400399
</div>
401-
) :
400+
) :
402401
''
403402
)}
404403
</div>

app/src/context/HTMLTypes.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ const HTMLTypes: HTMLType[] = [
9797
placeHolderShort: 'Header 2',
9898
placeHolderLong: '',
9999
icon: HeaderIcon
100-
},
101-
{
102-
id: 12,
103-
tag: 'strong',
104-
name: 'Strong',
105-
style: {},
106-
placeHolderShort: 'Strong',
107-
placeHolderLong: '',
108-
icon: null
109100
}
110101
];
111102

app/src/helperFunctions/generateCode.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Component, State, ChildElement } from '../interfaces/Interfaces';
1+
import { Component, State, ChildElement, HTMLType } from '../interfaces/Interfaces';
22
// import HTMLTypes from '../context/HTMLTypes';
33
import initialState from '../context/initialState';
44

5-
const test = document.getElementsByClassName("makeStyles-HTMLPanelItem-27");
6-
console.log(test);
5+
76

87
declare global {
98
interface Window {
@@ -16,7 +15,8 @@ const generateUnformattedCode = (
1615
comps: Component[],
1716
componentId: number,
1817
rootComponents: number[],
19-
projectType: string
18+
projectType: string,
19+
HTMLTypes: HTMLType[]
2020
) => {
2121
const components = [...comps];
2222
// find the component that we're going to generate code for
@@ -40,8 +40,8 @@ const generateUnformattedCode = (
4040
child['name'] = referencedComponent.name;
4141
return child;
4242
} else if (child.type === 'HTML Element') {
43-
const referencedHTML = initialState.HTMLTypes.find(elem => elem.id === child.typeId);
44-
console.log("ARRAY OF HTMLS: ", initialState.HTMLTypes);
43+
const referencedHTML = HTMLTypes.find(elem => elem.id === child.typeId);
44+
console.log("ARRAY OF HTMLS: ", HTMLTypes);
4545
console.log("REF HTML: ", referencedHTML);
4646
child['tag'] = referencedHTML.tag;
4747
if (referencedHTML.tag === 'div') {
@@ -247,7 +247,8 @@ const generateCode = (
247247
components: Component[],
248248
componentId: number,
249249
rootComponents: number[],
250-
projectType: string
250+
projectType: string,
251+
HTMLTypes: HTMLType[]
251252
) => {
252253
// console.log('components', components);
253254
// console.log('componentId', componentId);
@@ -257,7 +258,8 @@ const generateCode = (
257258
components,
258259
componentId,
259260
rootComponents,
260-
projectType
261+
projectType,
262+
HTMLTypes
261263
);
262264
return formatCode(code);
263265
};

app/src/reducers/componentReducer.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const reducer = (state: State, action: Action) => {
105105
return isChild;
106106
}
107107

108-
const updateIds = (components: Array<Object>) => {
108+
const updateIds = (components: Component[]) => {
109109
components.forEach((comp, i) => comp.id = i + 1);
110110
}
111111

@@ -187,7 +187,7 @@ const reducer = (state: State, action: Action) => {
187187
}
188188
// if there is a childId (childId here references the direct parent of the new child) find that child and a new child to its children array
189189

190-
190+
191191
else {
192192
const directParent = findChild(parentComponent, childId);
193193
directParent.children.push(newChild);
@@ -197,7 +197,8 @@ const reducer = (state: State, action: Action) => {
197197
components,
198198
parentComponentId,
199199
[...state.rootComponents],
200-
state.projectType
200+
state.projectType,
201+
state.HTMLTypes
201202
);
202203

203204
const canvasFocus = {
@@ -246,7 +247,8 @@ const reducer = (state: State, action: Action) => {
246247
components,
247248
state.canvasFocus.componentId,
248249
[...state.rootComponents],
249-
state.projectType
250+
state.projectType,
251+
state.HTMLTypes
250252
);
251253

252254
return { ...state, components };
@@ -276,7 +278,8 @@ const reducer = (state: State, action: Action) => {
276278
components,
277279
state.canvasFocus.componentId,
278280
[...state.rootComponents],
279-
state.projectType
281+
state.projectType,
282+
state.HTMLTypes
280283
);
281284

282285
return { ...state, components };
@@ -306,7 +309,8 @@ const reducer = (state: State, action: Action) => {
306309
components,
307310
state.canvasFocus.componentId,
308311
[...state.rootComponents],
309-
state.projectType
312+
state.projectType,
313+
state.HTMLTypes
310314
);
311315
const canvasFocus = { ...state.canvasFocus, childId: null };
312316
return { ...state, components, canvasFocus };
@@ -333,18 +337,18 @@ const reducer = (state: State, action: Action) => {
333337
// check if component is a child element of a page
334338
if(isChildOfPage(id)) {
335339
// TODO: include name of parent in alert
336-
// TODO: change canvas focus to parent
340+
// TODO: change canvas focus to parent
337341
//dialog.showErrorBox('error','Reusable components inside of a page must be deleted from the page');
338342
alert('Reusable components inside of a page must be deleted from the page');
339343
//const canvasFocus:Object = { componentId: id, childId: null };
340344
return { ...state }
341345
}
342346
// filter out components that don't match id
343-
const components: Array<Object> = [...state.components].filter(comp => comp.id != id);
347+
const components: Component[] = [...state.components].filter(comp => comp.id != id);
344348

345349
updateIds(components);
346350

347-
// TODO: temporary fix. should point to id directly
351+
// TODO: temporary fix. should point to id directly
348352
const canvasFocus = { componentId: 1, childId: null };
349353
return {...state, components, canvasFocus};
350354
}
@@ -375,7 +379,8 @@ const reducer = (state: State, action: Action) => {
375379
components,
376380
component.id,
377381
[...state.rootComponents],
378-
projectType
382+
projectType,
383+
state.HTMLTypes
379384
);
380385
});
381386

0 commit comments

Comments
 (0)