Skip to content

Commit b24ebd6

Browse files
committed
Merge branch 'Miko' of https://github.com/oslabs-beta/ReacType into calvin
2 parents 2e96471 + 4a85c2c commit b24ebd6

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

app/src/components/main/DemoRender.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ const DemoRender = (): JSX.Element => {
4242
document.querySelectorAll('a').forEach(element => {
4343
element.addEventListener('click', (event) => {
4444
event.preventDefault();
45-
window.top.postMessage(event.target.href, '*');
46-
})
45+
window.top.postMessage(event.currentTarget.href, '*');
46+
//document.body.style.backgroundColor = 'orange';
47+
}, true)
4748
});
4849
} catch (err) {
4950
const app = document.querySelector('#app');
@@ -57,6 +58,7 @@ const DemoRender = (): JSX.Element => {
5758

5859
//Switch between components when clicking on a link in the live render
5960
window.onmessage = (event) => {
61+
if(event.data === undefined) return;
6062
const component = event.data?.split('/').at(-1);
6163
const componentId = component && state.components?.find((el) => {
6264
return el.name.toLowerCase() === component.toLowerCase();
@@ -70,7 +72,6 @@ const DemoRender = (): JSX.Element => {
7072
const componentBuilder = (array: object, key: number = 0) => {
7173
const componentsToRender = [];
7274
for (const element of array) {
73-
7475
if (element.name !== 'separator') {
7576
const elementType = element.name;
7677
const childId = element.childId;
@@ -79,13 +80,13 @@ const DemoRender = (): JSX.Element => {
7980
const classRender = element.attributes.cssClasses;
8081
const activeLink = element.attributes.compLink;
8182
let renderedChildren;
82-
if (elementType !== 'input' && elementType !== 'img' && element.children.length > 0) {
83+
if (elementType !== 'input' && elementType !== 'img' && elementType !== 'Image' && element.children.length > 0) {
8384
renderedChildren = componentBuilder(element.children);
8485
}
8586
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
8687
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
8788
else if (elementType === 'Image') componentsToRender.push(<Box component='img' src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
88-
else if (elementType === 'a' || elementType === 'Link') componentsToRender.push(<Box component='a' href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}</Box>);
89+
else if (elementType === 'a' || elementType === 'Link') componentsToRender.push(<Box component='a' href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>);
8990
else if (elementType === 'Switch') componentsToRender.push(<Switch>{renderedChildren}</Switch>);
9091
else if (elementType === 'Route') componentsToRender.push(<Route exact path={activeLink}>{renderedChildren}</Route>);
9192
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>
@@ -98,9 +99,10 @@ const DemoRender = (): JSX.Element => {
9899

99100
let code = '';
100101
const currComponent = state.components.find(element => element.id === state.canvasFocus.componentId);
102+
101103
componentBuilder(currComponent.children).forEach(element => {
102104
try{
103-
code += ReactDOMServer.renderToString(element)
105+
code += ReactDOMServer.renderToString(element);
104106
} catch {
105107
return;
106108
}

app/src/reducers/componentReducer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ const reducer = (state: State, action: Action) => {
397397
const canvasFocus = { ...state.canvasFocus, componentId, childId };
398398
//makes it so the code preview will update when clicking on a new component
399399
const components = state.components.map(element => {
400+
console.log('element', element);
400401
return Object.assign({}, element);
401402
});
402403
return { ...state, components, canvasFocus };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reactype",
3-
"version": "10.0.0",
3+
"version": "11.0.0",
44
"description": "Prototyping tool for React/Typescript Applications.",
55
"private": true,
66
"main": "app/electron/main.js",

0 commit comments

Comments
 (0)