Skip to content

Commit a4b6bd6

Browse files
committed
canvas
2 parents f6a0f8b + 2a650b9 commit a4b6bd6

40 files changed

+485
-264
lines changed

app/electron/main.js

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ const isDev =
2929
const port = 8080;
3030
const selfHost = `http://localhost:${port}`;
3131

32-
// main.js is what controls the lifecycle of the electron application
32+
// main.js is what controls the lifecycle of the electron applicaton
3333

3434
// Keep a global reference of the window object, if you don't, the window will
3535
// be closed automatically when the JavaScript object is garbage collected.
3636
let win;
3737
let menuBuilder;
3838

39-
// function to create a new browser window
39+
// function to create a new broswer window
4040
// this function will be called when Electron has initialized itself
4141
async function createWindow() {
4242
if (isDev) {
@@ -55,24 +55,25 @@ async function createWindow() {
5555
// full screen
5656
width: 1920,
5757
height: 1080,
58+
minWidth: 980,
5859
// window title
5960
title: `ReacType`,
60-
// the browser window will not display initially as it's loading
61+
// the browser window will not display intiially as it's loading
6162
// once the browser window renders, a function is called below that hides the splash screen and displays the browser window
6263
show: false,
6364
// icon: path.join(__dirname, '../src/public/icons/png/256x256.png'),
6465
webPreferences: {
6566
zoomFactor: 0.7,
6667
// enable devtools when in development mode
6768
devTools: isDev,
68-
// crucial security feature - blocks rendering process from having access to node modules
69+
// crucial security feature - blocks rendering process from having access to node moduels
6970
nodeIntegration: false,
7071
// web workers will not have access to node
7172
nodeIntegrationInWorker: false,
72-
// disallow experimental feature to allow node.js support in sub-frames (i-frames/child windows)
73+
// disallow experimental feature to allow node.js suppport in subframes (iframes/child windows)
7374
nodeIntegrationInSubFrames: false,
74-
// runs electron apis and preload script in a separate JS context
75-
// separate context has access to document/window but has it's own built-ins and is isolate from changes to global environment by loaded page
75+
// runs electron apis and preload script in a seperate JS context
76+
// sepearate context has access to document/window but has it's own built-ins and is isolate from chagnes to gloval environment by locaded page
7677
// Electron API only available from preload, not loaded page
7778
contextIsolation: true,
7879
// disables remote module. critical for ensuring that rendering process doesn't have access to node functionality
@@ -100,7 +101,7 @@ async function createWindow() {
100101

101102
// Load app
102103
if (isDev) {
103-
// load app from web-dev server
104+
// load app from webdev server
104105
win.loadURL(selfHost);
105106
} else {
106107
// load local file if in production
@@ -223,8 +224,10 @@ app.on('web-contents-created', (event, contents) => {
223224
selfHost,
224225
'http://localhost:5000',
225226
'https://reactype.herokuapp.com',
226-
'https://github.com/'
227+
'https://github.com/',
228+
'https://nextjs.org',
227229
];
230+
console.log('parsed URL origin', parsedUrl.origin);
228231
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
229232
if (!validOrigins.includes(parsedUrl.origin)) {
230233
console.error(
@@ -233,7 +236,7 @@ app.on('web-contents-created', (event, contents) => {
233236
// if the requested URL is not in the whitelisted array, then don't navigate there
234237
event.preventDefault();
235238
return;
236-
}
239+
} else console.log(`Successful navigation to ${parsedUrl}`);
237240
});
238241

239242
contents.on('will-redirect', (event, navigationUrl) => {
@@ -242,8 +245,8 @@ app.on('web-contents-created', (event, contents) => {
242245
selfHost,
243246
'http://localhost:5000',
244247
'https://reactype.herokuapp.com',
245-
'https://github.com',
246-
'app://rse/'
248+
'https://github.com/',
249+
'https://nextjs.org',
247250
];
248251

249252
// Log and prevent the app from redirecting to a new page
@@ -257,12 +260,12 @@ app.on('web-contents-created', (event, contents) => {
257260

258261
event.preventDefault();
259262
return;
260-
}
263+
} else console.log('Succesful link sent to browser');
261264
});
262265

263266
// https://electronjs.org/docs/tutorial/security#11-verify-webview-options-before-creation
264267
// The web-view is used to embed guest content in a page
265-
// This event listener deletes web-views if they happen to occur in the app
268+
// This event listener deletes webviews if they happen to occur in the app
266269
// https://www.electronjs.org/docs/api/web-contents#event-will-attach-webview
267270
contents.on('will-attach-webview', (event, webPreferences, params) => {
268271
// Strip away preload scripts if unused or verify their location is legitimate
@@ -276,12 +279,26 @@ app.on('web-contents-created', (event, contents) => {
276279
// https://electronjs.org/docs/tutorial/security#13-disable-or-limit-creation-of-new-windows
277280
contents.on('new-window', async (event, navigationUrl) => {
278281
// Log and prevent opening up a new window
279-
console.error(
280-
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`
281-
);
282-
283-
event.preventDefault();
284-
return;
282+
const parsedUrl = new URL(navigationUrl);
283+
const validOrigins = [
284+
selfHost,
285+
'http://localhost:5000',
286+
'https://reactype.herokuapp.com',
287+
'https://github.com/',
288+
'https://nextjs.org',
289+
];
290+
console.log('parsed URL origin', parsedUrl.origin);
291+
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
292+
if (!validOrigins.includes(parsedUrl.origin)) {
293+
console.error(
294+
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`
295+
);
296+
// if the requested URL is not in the whitelisted array, then don't navigate there
297+
event.preventDefault();
298+
return;
299+
} else console.log(`Successful new window to ${parsedUrl}`);
300+
// event.preventDefault();
301+
// return;
285302
});
286303
});
287304

@@ -360,9 +377,15 @@ ipcMain.on('delete_cookie', event => {
360377
.catch(err => console.log('Error deleting cookie:', err));
361378
});
362379

363-
// opens new window for github oauth when button on sign in page is clicked
380+
// opens new window for github oauth when button on signin page is clicked
364381
ipcMain.on('github', event => {
365-
// create new browser window object with size, title, security options
382+
// your github applications credentials
383+
const options = {
384+
client_id: 'your_client_id',
385+
client_secret: 'your_client_secret',
386+
scopes: ['user:email', 'notifications']
387+
};
388+
// create new browserwindow object with size, title, security options
366389
const github = new BrowserWindow({
367390
width: 800,
368391
height: 600,
@@ -376,8 +399,11 @@ ipcMain.on('github', event => {
376399
zoomFactor: 1.0
377400
}
378401
});
402+
const githubUrl = 'https://github.com/login/oauth/authorize?';
403+
const authUrl =
404+
githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
379405
// redirects to relevant server endpoint
380-
github.loadURL(`${serverUrl}/github`);
406+
github.loadURL(authUrl);
381407
// show window
382408
github.show();
383409
// if final callback is reached and we get a redirect from server back to our app, close oauth window
@@ -399,10 +425,11 @@ ipcMain.on('github', event => {
399425
});
400426

401427
ipcMain.on('tutorial', event => {
402-
// create new browser window object with size, title, security options
428+
// create new browserwindow object with size, title, security options
403429
const tutorial = new BrowserWindow({
404430
width: 800,
405431
height: 600,
432+
minWidth: 661,
406433
title: 'Tutorial',
407434
webPreferences: {
408435
nodeIntegration: false,
@@ -435,8 +462,4 @@ ipcMain.on('tutorial', event => {
435462
// });
436463
});
437464

438-
439-
440-
441-
442465
//module.exports = dialog;

app/electron/menu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var MenuBuilder = function(mainWindow, appName) {
1818
const tutorial = new BrowserWindow({
1919
width: 1224,
2020
height: 1024,
21+
minWidth: 661,
2122
title: 'Tutorial',
2223
webPreferences: {
2324
nodeIntegration: false,
@@ -26,7 +27,7 @@ var MenuBuilder = function(mainWindow, appName) {
2627
contextIsolation: true,
2728
enableRemoteModule: false,
2829
zoomFactor: 1.0,
29-
// devTools: false
30+
devTools: false
3031
}
3132
});
3233
tutorial.loadURL(`http://localhost:8080/#/tutorial`);

app/src/components/bottom/CodePreview.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useState } from 'react';
1+
import React, { useContext, useState, useRef, useEffect } from 'react';
22
import { StateContext } from '../../context/context';
33
import AceEditor from 'react-ace';
44
import { makeStyles } from '@material-ui/core/styles';
@@ -9,21 +9,17 @@ import 'ace-builds/src-noconflict/theme-solarized_dark';
99
import 'ace-builds/src-noconflict/theme-solarized_light';
1010
import 'ace-builds/src-noconflict/theme-terminal';
1111
import { Component } from '../../interfaces/Interfaces';
12-
13-
// const useStyles = makeStyles(theme => ({
14-
// formControl: {
15-
// margin: theme.spacing(1),
16-
// minWidth: 120
17-
// },
18-
// selectEmpty: {
19-
// marginTop: theme.spacing(2)
20-
// }
21-
// }));
22-
23-
// const optionColor = '#252526';
12+
import useResizeObserver from '../../tree/useResizeObserver';
2413

2514
const CodePreview = ({ theme, setTheme }) => {
15+
const wrapper = useRef();
16+
//console.log(wrapper.current);
17+
const dimensions = useResizeObserver(wrapper);
18+
const { width, height } =
19+
dimensions || 0;
20+
2621
const [state, dispatch] = useContext(StateContext);
22+
const [divHeight, setDivHeight] = useState(0);
2723
// const classes = useStyles();
2824
const currentComponent = state.components.find(
2925
(elem: Component) => elem.id === state.canvasFocus.componentId
@@ -37,14 +33,21 @@ const CodePreview = ({ theme, setTheme }) => {
3733
setTheme(e.target.value);
3834
};
3935

36+
useEffect(() => {
37+
setDivHeight(height);
38+
//console.log(divHeight);
39+
}, [height])
40+
4041
return (
4142
<div
43+
ref={wrapper}
4244
style={{
4345
height: '90%',
4446
maxWidth: '100%',
4547
justifyContent: 'center'
4648
}}
4749
>
50+
{/* <h1>{divHeight}</h1> */}
4851
<AceEditor
4952
mode="javascript"
5053
theme={theme}

app/src/components/left/HTMLPanel.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ import { makeStyles } from '@material-ui/core/styles';
66

77
const HTMLPanel = (): JSX.Element => {
88
const classes = useStyles();
9+
const [state, dispatch] = useContext(StateContext);
10+
11+
let startingID = 0;
12+
for (let i = 0; i < state.HTMLTypes.length; i+=1) {
13+
if (state.HTMLTypes[i].id >= startingID) {
14+
startingID = state.HTMLTypes[i].id;
15+
}
16+
}
17+
startingID += 1;
918

1019
const [tag, setTag] = useState('');
1120
const [name, setName] = useState('');
12-
const [currentID, setCurrentID] = useState(12);
13-
const [state, dispatch] = useContext(StateContext);
21+
const [currentID, setCurrentID] = useState(startingID);
1422
const [errorMsg, setErrorMsg] = useState('');
1523
const [errorStatus, setErrorStatus] = useState(false);
1624

@@ -81,14 +89,8 @@ const HTMLPanel = (): JSX.Element => {
8189
type: 'ADD ELEMENT',
8290
payload: newElement
8391
});
84-
let nextID = 0;
85-
for (let i = 0; i < state.HTMLTypes.length; i+=1) {
86-
if (state.HTMLTypes[i].id > nextID) {
87-
nextID = state.HTMLTypes.id;
88-
}
89-
}
90-
nextID += 1;
91-
setCurrentID(nextID);
92+
93+
setCurrentID(currentID + 1);
9294
setTag('');
9395
setName('');
9496
};

app/src/components/login/SignIn.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { makeStyles, withStyles } from '@material-ui/core/styles';
2222
import Container from '@material-ui/core/Container';
2323
import GitHubIcon from '@material-ui/icons/GitHub';
2424
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
25+
import { ipcRenderer } from 'electron';
2526

2627
function Copyright() {
2728
return (
@@ -111,12 +112,12 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
111112
};
112113

113114
/*
114-
Response Options:
115+
Response Options:
115116
Success
116117
Error
117-
No Username Input
118-
No Password Input
119-
Incorrect Password
118+
No Username Input
119+
No Password Input
120+
Incorrect Password
120121
Invalid Username
121122
*/
122123
const handleLogin = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
@@ -226,7 +227,9 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
226227
className={classes.submit}
227228
onClick={() => {
228229
// messages the main proces to open new window for github oauth
229-
console.log('open github')
230+
console.log('open github');
231+
console.log(window.api);
232+
// ipcRenderer.send('github-oauth', 'getToken');
230233
window.api.github();
231234
}}
232235
>

app/src/components/main/Canvas.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ import { Component, DragItem } from '../../interfaces/Interfaces';
66
import { combineStyles } from '../../helperFunctions/combineStyles';
77
import renderChildren from '../../helperFunctions/renderChildren';
88

9+
const findNestedChild = (curr, components) => {
10+
components.forEach((comp, i) => {
11+
comp.children.forEach(child => {
12+
if (child.name === curr.name) console.log(child.name)
13+
});
14+
if (comp.children.length !== 0) findNestedChild(curr, comp.children);
15+
});
16+
}
17+
918
function Canvas() {
1019
const [state, dispatch] = useContext(StateContext);
11-
console.log('state.comps', state.components);
1220

1321
// find the current component to render on the canvas
1422
const currentComponent: Component = state.components.find(
1523
(elem: Component) => elem.id === state.canvasFocus.componentId
1624
);
1725

26+
findNestedChild(currentComponent, state.components);
27+
1828
// changes focus of the canvas to a new component / child
1929
const changeFocus = (componentId: number, childId: number | null) => {
2030
dispatch({ type: 'CHANGE FOCUS', payload: { componentId, childId } });

0 commit comments

Comments
 (0)