Skip to content

Commit 4826f30

Browse files
committed
changes in DemoRender added
1 parent c83efba commit 4826f30

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

app/src/components/main/DemoRender.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useContext } from 'react';
1+
import React, { useState, useEffect, useRef, useContext } from 'react';
22
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
33
import Box from '@material-ui/core/Box';
44
import cssRefresher from '../../helperFunctions/cssRefresh';
@@ -9,14 +9,28 @@ import { Component } from '../../interfaces/Interfaces';
99
// DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
1010
// real react components that utilize hot module reloading to depict the user's prototype application.
1111
const DemoRender = (): JSX.Element => {
12-
1312
const [state,] = useContext(StateContext);
13+
console.log('state line 14', state);
1414
let currentComponent = state.components.find(
1515
(elem: Component) => elem.id === state.canvasFocus.componentId
1616
);
1717

18+
// const iframe = useRef<any>(); --> we already have this on line 36
19+
// const [components, setComponents] = useState([]);
20+
// const [state, dispatch] = useContext(StateContext);
21+
// const [codeRender, setCodeRender] = useState('') --> not sure about what this does
22+
// const demoContainerStyle = {
23+
// width: '100%',
24+
// backgroundColor: '#FBFBFB',
25+
// border: '2px Solid grey',
26+
// };
27+
28+
29+
30+
31+
1832
console.log('state in DemoRender', state);
19-
console.log('currentComponent', currentComponent);
33+
console.log('currentComponent.code', currentComponent.code);
2034

2135
// Create React ref to inject transpiled code in inframe
2236
const iframe = useRef<any>();
@@ -26,13 +40,15 @@ const DemoRender = (): JSX.Element => {
2640
border: '2px Solid grey',
2741
};
2842

29-
// let code = useSelector((state) => state.code);
30-
let code = `<div style="color: red">Will this work?</div><div>second</div>`
31-
const html = `<html>
32-
<head>
33-
</head>
43+
let code = useSelector((state) => state.code);
44+
45+
const html = `
46+
<html>
47+
<head>
48+
</head>
3449
<body>
3550
<div id="app">
51+
<h1>HELLO WORLD</h1>
3652
</div>
3753
<script>
3854
window.addEventListener('message', (event) => {
@@ -77,12 +93,14 @@ const DemoRender = (): JSX.Element => {
7793
return componentsToRender;
7894
};
7995

96+
8097
useEffect(() => {
8198
cssRefresher();
8299
}, [])
83100

84101
useEffect(() => {
85-
iframe.current.contentWindow.postMessage(code, '*');
102+
console.log('code', code);
103+
iframe.current.contentWindow.postMessage(code, '*');
86104
}, [code])
87105

88106
return (

0 commit comments

Comments
 (0)