Skip to content

Commit 2a650b9

Browse files
authored
Merge pull request #27 from diegovazquezny/fix-del
Fix del
2 parents f74aaf9 + 58b4aac commit 2a650b9

File tree

13 files changed

+135
-51
lines changed

13 files changed

+135
-51
lines changed

app/electron/main.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ app.on('web-contents-created', (event, contents) => {
224224
selfHost,
225225
'http://localhost:5000',
226226
'https://reactype.herokuapp.com',
227-
'https://github.com/'
227+
'https://github.com/',
228+
'https://nextjs.org',
228229
];
230+
console.log('parsed URL origin', parsedUrl.origin);
229231
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
230232
if (!validOrigins.includes(parsedUrl.origin)) {
231233
console.error(
@@ -234,7 +236,7 @@ app.on('web-contents-created', (event, contents) => {
234236
// if the requested URL is not in the whitelisted array, then don't navigate there
235237
event.preventDefault();
236238
return;
237-
}
239+
} else console.log(`Successful navigation to ${parsedUrl}`);
238240
});
239241

240242
contents.on('will-redirect', (event, navigationUrl) => {
@@ -243,8 +245,8 @@ app.on('web-contents-created', (event, contents) => {
243245
selfHost,
244246
'http://localhost:5000',
245247
'https://reactype.herokuapp.com',
246-
'https://github.com',
247-
'app://rse/'
248+
'https://github.com/',
249+
'https://nextjs.org',
248250
];
249251

250252
// Log and prevent the app from redirecting to a new page
@@ -258,7 +260,7 @@ app.on('web-contents-created', (event, contents) => {
258260

259261
event.preventDefault();
260262
return;
261-
}
263+
} else console.log('Succesful link sent to browser');
262264
});
263265

264266
// https://electronjs.org/docs/tutorial/security#11-verify-webview-options-before-creation
@@ -277,12 +279,26 @@ app.on('web-contents-created', (event, contents) => {
277279
// https://electronjs.org/docs/tutorial/security#13-disable-or-limit-creation-of-new-windows
278280
contents.on('new-window', async (event, navigationUrl) => {
279281
// Log and prevent opening up a new window
280-
console.error(
281-
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`
282-
);
283-
284-
event.preventDefault();
285-
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;
286302
});
287303
});
288304

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/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 } });

app/src/containers/RightContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ const RightContainer = (): JSX.Element => {
215215
};
216216

217217
const handleDeleteReusableComponent = () => {
218-
/*isChildOfPage()
218+
isChildOfPage()
219219
? handleDialogError('component')
220-
:*/ dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
220+
: dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
221221
};
222222

223223
const isReusable = (configTarget): boolean => {

app/src/reducers/componentReducer.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ const reducer = (state: State, action: Action) => {
127127
}
128128

129129
const deleteComponentFromPages = (components, name) => {
130+
console.log('name', name);
130131
const searchNestedComps = (childComponents) => {
131-
console.log(childComponents);
132-
if (childComponents.length === 0) return;
133-
childComponents.forEach((comp, i) => {
134-
if (comp.isPage){
135-
comp.children.forEach((child, i, arr) => {
136-
if (child.name === name) {
137-
arr.splice(i, 1);
138-
}
139-
})
140-
}
141-
searchNestedComps(childComponents.children)
142-
});
132+
console.log('child components', childComponents);
133+
// if (childComponents.length === 0) return console.log('empty children array');
134+
// childComponents.forEach((comp, i, arr) => {
135+
// console.log('each individual comp', comp);
136+
// if (comp.name === name){
137+
// arr.splice(i, 1);
138+
// } else searchNestedComps(childComponents.children)
139+
// });
143140
}
144-
components.forEach(comp => searchNestedComps(comp.children));
141+
components.forEach(comp => {
142+
console.log('current comp', comp);
143+
searchNestedComps(comp.children)
144+
});
145145
console.log(components);
146146
}
147147

@@ -393,7 +393,7 @@ const reducer = (state: State, action: Action) => {
393393
updateIds(components);
394394

395395
// check if reusable comp is inside a page
396-
deleteComponentFromPages(components, name);
396+
//deleteComponentFromPages(components, name);
397397

398398
const canvasFocus = { componentId: 1, childId: null };
399399

app/src/tutorial/RouteLinks.tsx

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,78 @@
11
import React from 'react';
2-
import { Link, RouteComponentProps } from 'react-router-dom';
3-
2+
import { Link, withRouter, RouteComponentProps } from 'react-router-dom';
3+
import { makeStyles } from '@material-ui/core/styles';
4+
import links2 from '../../../resources/route_links_tutorial_images/links2.png';
5+
import links3 from '../../../resources/route_links_tutorial_images/links3.png';
6+
import links4 from '../../../resources/route_links_tutorial_images/links4.png';
7+
import links6 from '../../../resources/route_links_tutorial_images/links6.png';
8+
import linksCanvas from '../../../resources/route_links_tutorial_images/links-canvas.png';
49
// import Grid from '@material-ui/core/Grid';
510

611
// import ComponentPanel from '../components/left/ComponentPanel';
712
// import HTMLPanel from '../components/left/HTMLPanel';
813

914
// Left-hand portion of the app, where component options are displayed
1015

11-
const RouteLinks: React.FC<{
12-
classes: any;
13-
setPage: Function;
14-
}> = ({ classes, setPage }) => {
16+
const ComponentTree: React.FC<RouteComponentProps> = () => {
17+
const body = document.querySelector('body');
18+
body.style.overflowY = 'auto';
19+
const useStyles = makeStyles({
20+
title: {
21+
color: '#14151f',
22+
fontSize: 54
23+
},
24+
text: {
25+
color: '#2e2f3e',
26+
fontSize: 24
27+
},
28+
wrapper: {
29+
margin: '30px 30px 30px 30px',
30+
width: 'auto'
31+
},
32+
smallImg: {
33+
borderRadius: '3px',
34+
height: '300px',
35+
marginRight: '20px'
36+
},
37+
largeImg: {
38+
height: '700px'
39+
},
40+
imgWrapper: {
41+
display: 'flex',
42+
flexDirection: 'row',
43+
alignItems: 'center',
44+
// border: '1px solid black',
45+
width: 'auto'
46+
}
47+
});
48+
const classes = useStyles();
1549
return (
16-
<div>
17-
RouteLinks
50+
<div className={classes.wrapper}>
51+
<h1 className={classes.title}>Next.js Route Links</h1>
52+
<h2>Route Links are only available for Next.js projects.</h2>
53+
<p className={classes.text}>Users are able to drag-and-drop 'Link' components onto the canvas which allow navigation to different pages.</p>
54+
<div className={classes.imgWrapper}>
55+
<img className={classes.largeImg} src={linksCanvas}></img>
56+
</div>
57+
<p className={classes.text}>Each page found in the 'Pages' section can be navigated to via a 'Link'. Clicking on the 'Route Link' dropdown will display all the created pages in your application.</p>
58+
<div className={classes.imgWrapper}>
59+
<img className={classes.smallImg} src={links2}></img>
60+
<img className={classes.smallImg} src={links3}></img>
61+
</div>
62+
<p className={classes.text}>The code generator will automatically <code>import Link from 'next/link'</code> and create your Link component in the bottom panel.</p>
63+
<div className={classes.imgWrapper}>
64+
<img className={classes.largeImg} src={links4}></img>
65+
</div>
66+
<p className={classes.text}>Clicking on a Link component on the canvas will navigate to the corresponding page.</p>
67+
<div className={classes.imgWrapper}>
68+
<img className={classes.smallImg} src={links6}></img>
69+
</div>
70+
<p className={classes.text}>For more information on 'Link' for Next.js, please <a href="https://nextjs.org/docs/api-reference/next/link" target="_blank">visit the official documentation on nextjs.org.</a></p>
71+
<Link to={`/tutorial`}>
72+
<button>Tutorial</button>
73+
</Link>
1874
</div>
1975
);
2076
};
2177

22-
export default RouteLinks;
23-
78+
export default withRouter(ComponentTree);
Loading
3.11 KB
Loading
3.17 KB
Loading
6.92 KB
Loading
38.3 KB
Loading
5.83 KB
Loading
4.16 KB
Loading

0 commit comments

Comments
 (0)