Skip to content

Commit 28754db

Browse files
Merge pull request #6 from oslabs-beta/stephen-feature
ready for launch
2 parents c5debc1 + 3dcbff1 commit 28754db

File tree

10 files changed

+66
-64
lines changed

10 files changed

+66
-64
lines changed

app/electron/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ async function createWindow() {
5252
// await installExtension([REACT_DEVELOPER_TOOLS])
5353
// .then(name => console.log(`Added Extension: ${name}`))
5454
// .catch(err => console.log('An error occurred: ', err));
55-
console.log("install extention");
5655
} else {
5756
// this will happen before creating the browser window. it returns a Boolean whether the protocol of scheme 'app://' was successfully registered and a file (index-prod.html) was sent as the response
5857
protocol.registerBufferProtocol(Protocol.scheme, Protocol.requestHandler);

app/src/components/bottom/CodePreview.tsx

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ import 'ace-builds/src-noconflict/theme-monokai';
1111
import 'ace-builds/src-noconflict/theme-terminal';
1212
import { Component } from '../../interfaces/Interfaces';
1313
import useResizeObserver from '../../tree/useResizeObserver';
14-
import { string } from 'prop-types';
1514
import { unpkgPathPlugin } from '../../plugins/unpkg-path-plugin';
1615
import { fetchPlugin } from '../../plugins/fetch-plugin';
1716
import * as esbuild from 'esbuild-wasm';
18-
import { useSelector, useDispatch } from 'react-redux';
1917
import { store } from './../../index';
20-
2118
const CodePreview: React.FC<{
2219
theme: string | null;
2320
setTheme: any | null;
@@ -35,25 +32,21 @@ const CodePreview: React.FC<{
3532
})
3633
}
3734

35+
36+
3837
const wrapper = useRef();
3938
const dimensions = useResizeObserver(wrapper);
4039
const { width, height } =
4140
dimensions || 0;
4241

4342
const [state, dispatch] = useContext(StateContext);
4443
const [divHeight, setDivHeight] = useState(0);
45-
const currentComponent = state.components.find(
44+
let currentComponent = state.components.find(
4645
(elem: Component) => elem.id === state.canvasFocus.componentId
4746
);
48-
const [input, setInput] = useState(currentComponent.code);
49-
50-
console.log('this is state', state.components)
51-
console.log('currentcomponent.code', currentComponent.code)
5247

48+
const [input, setInput] = useState();
5349

54-
const handleCodeSnipChange = (val) => {
55-
currentComponent.code = val;
56-
};
5750

5851
useEffect(() => {
5952
startService();
@@ -64,36 +57,37 @@ const CodePreview: React.FC<{
6457
}, [height])
6558

6659
useEffect(() => {
67-
setInput(currentComponent.code)
68-
}, [state])
60+
61+
setInput(currentComponent.code);
62+
store.dispatch({type: "INPUT", payload: currentComponent.code});
63+
}, [state.components])
6964

7065

71-
const handleChange = (data) => {
72-
setInput(data)
73-
console.log('line 69',input)
74-
};
7566

76-
const handleClick = async () => {
77-
// setInput(currentComponent.code)
78-
// console.log('currentComponent.code', currentComponent.code)
67+
68+
const handleChange = async (data) => {
69+
setInput(data);
70+
71+
store.dispatch({type: "INPUT", payload: data});
7972
if(!ref.current) {
8073
return;
8174
}
82-
const result = await ref.current.build({
75+
let result = await ref.current.build({
8376
entryPoints: ['index.js'],
8477
bundle: true,
8578
write: false,
79+
incremental:true,
80+
minify: true,
8681
plugins: [
8782
unpkgPathPlugin(),
88-
fetchPlugin(input)
83+
fetchPlugin(data)
8984
],
9085
define: {
91-
'process.env.NODE_ENV': '"development"',
86+
'process.env.NODE_ENV': '"production"',
9287
global: 'window'
9388
}
9489
})
95-
console.log('this is input',input)
96-
store.dispatch({type: "SAVE", payload: result.outputFiles[0].text});
90+
store.dispatch({type: "SAVE", payload: result.outputFiles[0].text});
9791
}
9892

9993

@@ -110,16 +104,15 @@ const CodePreview: React.FC<{
110104
mode="javascript"
111105
theme="monokai"
112106
width="100%"
113-
height="70%"
107+
height="100%"
114108
onChange={handleChange}
115-
// value={currentComponent.code}
116109
value={input}
117110
name="Code_div"
118111
readOnly={false}
119112
fontSize={16}
120113
tabSize={2}
121114
/>
122-
<button onClick={() => handleClick()}>Fetch</button>
115+
123116
</div>
124117
);
125118
};
@@ -128,3 +121,4 @@ export default CodePreview;
128121

129122

130123

124+

app/src/components/login/FBPassWord.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const SignUp: React.FC<LoginInt & RouteComponentProps> = props => {
133133
if (userCreated === 'Success') {
134134
props.history.push('/');
135135
} else {
136-
console.log(userCreated);
136+
137137
}
138138
});
139139
};

app/src/components/main/DemoRender.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
import React, {
33
useState, useCallback, useContext, useEffect, useRef
44
} from 'react';
5-
import ReactDOM from 'react-dom';
65
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
76
import Button from '@material-ui/core/Button';
87
import Box from '@material-ui/core/Box';
98
import StateContext from '../../context/context';
109
import cssRefresher from '../../helperFunctions/cssRefresh';
11-
import {store} from '../../../src/index';
1210
import { useSelector } from 'react-redux';
1311
// DemoRender is the full sandbox demo of our user's custom built React components. DemoRender references the design specifications stored in state to construct
1412
// real react components that utilize hot module reloading to depict the user's prototype application.
@@ -17,7 +15,6 @@ const DemoRender = (props): JSX.Element => {
1715
const iframe = useRef<any>();
1816
const [components, setComponents] = useState([]);
1917
const [state, dispatch] = useContext(StateContext);
20-
const [codeRender, setCodeRender] = useState('')
2118
const demoContainerStyle = {
2219
width: '100%',
2320
backgroundColor: '#FBFBFB',
@@ -30,11 +27,16 @@ const DemoRender = (props): JSX.Element => {
3027
<html>
3128
<head></head>
3229
<body>
33-
<div id='app'></div>
30+
<div id="app"></div>
3431
<script>
35-
window.addEventListener('message', (e) => {
36-
console.log(e)
37-
eval(e.data);
32+
window.addEventListener('message', (event) => {
33+
try {
34+
eval(event.data);
35+
} catch (err) {
36+
const app = document.querySelector('#app');
37+
app.innerHTML = '<div style="color: red;"><h4>Runtime Error</h4>' + err + '</div>';
38+
console.error(err);
39+
}
3840
}, false);
3941
</script>
4042
</body>
@@ -82,20 +84,16 @@ const DemoRender = (props): JSX.Element => {
8284
cssRefresher();
8385
}, [])
8486

85-
87+
8688
useEffect(() => {
87-
88-
console.log("code changed", code);
89-
setCodeRender(code)
9089
iframe.current.contentWindow.postMessage(code, '*');
91-
9290
}, [code])
9391

9492
return (
9593
<div id={'renderFocus'} style={demoContainerStyle}>
9694

9795

98-
<iframe ref={iframe} sandbox='allow-scripts' srcDoc={html} width='500px' height='500px'/>
96+
<iframe ref={iframe} sandbox='allow-scripts allow-popups allow-popups-to-escape-sandbox' srcDoc={html} width='100%' height='100%'/>
9997

10098

10199
</div>

app/src/helperFunctions/generateCode.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ const generateUnformattedCode = (
291291
${`import ReactDOM from 'react-dom';`}
292292
${importReactRouter ? `import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';`: ``}
293293
${importsMapped}
294-
${importContext}
295-
${providers}
296-
${context}
297294
${`const ${currComponent.name} = (props) => {`}
298295
${` const [value, setValue] = useState("");${writeStateProps(currComponent.useStateCodes)}`}
299296

app/src/index.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
HashRouter as Router,
44
Route,
55
Redirect,
6-
Switch,
6+
Switch
77
} from 'react-router-dom';
88
import 'babel-polyfill';
99
import React from 'react';
@@ -24,29 +24,27 @@ const client = new ApolloClient({
2424
uri: 'https://reactype-caret.herokuapp.com/graphql',
2525
cache: new InMemoryCache()
2626
});
27-
const initialState = {code: `
28-
import React from 'react';
29-
import ReactDOM from 'react-dom';
30-
const App = () => <h1>Hello World!</h1>
31-
32-
ReactDOM.render(<App />, document.querySelector('#app'));`}
27+
const initialState = { code: ``, input: `` };
3328
const rootReducer = (state = initialState, action) => {
34-
console.log('action', action);
3529
switch (action.type) {
3630
case 'SAVE':
37-
return {...state, code:action.payload};
31+
return { ...state, code: action.payload };
32+
case 'INPUT':
33+
return { ...state, input: action.payload };
3834
default:
39-
return state;
35+
return state;
4036
}
41-
42-
}
37+
};
4338

44-
export const store = createStore(rootReducer)
39+
export const store = createStore(
40+
rootReducer,
41+
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
42+
);
4543

4644
const PrivateRoute = ({ component: Component, ...rest }) => (
4745
<Route
4846
{...rest}
49-
render={ (props) => {
47+
render={props => {
5048
return Cookies.get('ssid') || window.localStorage.getItem('ssid') ? (
5149
<Component {...props} />
5250
) : (
@@ -71,6 +69,6 @@ ReactDOM.render(
7169
</Switch>
7270
</Router>
7371
</Provider>
74-
</ ApolloProvider>,
75-
document.getElementById('app'),
72+
</ApolloProvider>,
73+
document.getElementById('app')
7674
);

app/src/plugins/fetch-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const fetchPlugin = (inputCode: string) => {
4949

5050

5151
build.onLoad({ filter: /.*/ }, async (args: any) => {
52-
console.log('line 55 of fetch', args)
52+
5353
const cachedResult = await fileCache.getItem<esbuild.OnLoadResult>(args.path);
5454
if(cachedResult) {
5555
return cachedResult;

app/src/reducers.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const initialState = {code: ``}
2+
const rootReducer = (state = initialState, action) => {
3+
switch (action.type) {
4+
case 'CODE':
5+
return { ...state, code: action.payload };
6+
case 'ADD_CHILD':
7+
return { ...state, child: action.payload };
8+
case 'CHANGE_FOCUS':
9+
return { ...state, focus: action.payload };
10+
default:
11+
return state;
12+
}
13+
};
14+
15+
export default rootReducer;

app/src/reducers/componentReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ const reducer = (state: State, action: Action) => {
266266
typeId,
267267
childId
268268
}: { type: string; typeId: number; childId: any } = action.payload;
269-
console.log("action.payload", action.payload);
269+
270270
const parentComponentId: number = state.canvasFocus.componentId;
271271
const components = [...state.components];
272272

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
"source-map-support": "^0.5.19",
159159
"spectron": "^15.0.0",
160160
"uniqid": "^5.3.0",
161+
"use-debounce": "^7.0.1",
161162
"uuid": "^8.2.0"
162163
},
163164
"devDependencies": {

0 commit comments

Comments
 (0)