Skip to content

Commit dc423f2

Browse files
committed
code preview, canvas, reusable components tutorial
2 parents ddf78c6 + 3359154 commit dc423f2

File tree

14 files changed

+295
-164
lines changed

14 files changed

+295
-164
lines changed

app/electron/main.js

Lines changed: 13 additions & 13 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 applicaton
32+
// main.js is what controls the lifecycle of the electron application
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 broswer window
39+
// function to create a new browser window
4040
// this function will be called when Electron has initialized itself
4141
async function createWindow() {
4242
if (isDev) {
@@ -57,22 +57,22 @@ async function createWindow() {
5757
height: 1080,
5858
// window title
5959
title: `ReacType`,
60-
// the browser window will not display intiially as it's loading
60+
// the browser window will not display initially as it's loading
6161
// once the browser window renders, a function is called below that hides the splash screen and displays the browser window
6262
show: false,
6363
// icon: path.join(__dirname, '../src/public/icons/png/256x256.png'),
6464
webPreferences: {
6565
zoomFactor: 0.7,
6666
// enable devtools when in development mode
6767
devTools: isDev,
68-
// crucial security feature - blocks rendering process from having access to node moduels
68+
// crucial security feature - blocks rendering process from having access to node modules
6969
nodeIntegration: false,
7070
// web workers will not have access to node
7171
nodeIntegrationInWorker: false,
72-
// disallow experimental feature to allow node.js suppport in subframes (iframes/child windows)
72+
// disallow experimental feature to allow node.js support in sub-frames (i-frames/child windows)
7373
nodeIntegrationInSubFrames: false,
74-
// runs electron apis and preload script in a seperate JS context
75-
// 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
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
7676
// Electron API only available from preload, not loaded page
7777
contextIsolation: true,
7878
// disables remote module. critical for ensuring that rendering process doesn't have access to node functionality
@@ -100,7 +100,7 @@ async function createWindow() {
100100

101101
// Load app
102102
if (isDev) {
103-
// load app from webdev server
103+
// load app from web-dev server
104104
win.loadURL(selfHost);
105105
} else {
106106
// load local file if in production
@@ -262,7 +262,7 @@ app.on('web-contents-created', (event, contents) => {
262262

263263
// https://electronjs.org/docs/tutorial/security#11-verify-webview-options-before-creation
264264
// The web-view is used to embed guest content in a page
265-
// This event listener deletes webviews if they happen to occur in the app
265+
// This event listener deletes web-views if they happen to occur in the app
266266
// https://www.electronjs.org/docs/api/web-contents#event-will-attach-webview
267267
contents.on('will-attach-webview', (event, webPreferences, params) => {
268268
// Strip away preload scripts if unused or verify their location is legitimate
@@ -360,9 +360,9 @@ ipcMain.on('delete_cookie', event => {
360360
.catch(err => console.log('Error deleting cookie:', err));
361361
});
362362

363-
// opens new window for github oauth when button on signin page is clicked
363+
// opens new window for github oauth when button on sign in page is clicked
364364
ipcMain.on('github', event => {
365-
// create new browserwindow object with size, title, security options
365+
// create new browser window object with size, title, security options
366366
const github = new BrowserWindow({
367367
width: 800,
368368
height: 600,
@@ -399,7 +399,7 @@ ipcMain.on('github', event => {
399399
});
400400

401401
ipcMain.on('tutorial', event => {
402-
// create new browserwindow object with size, title, security options
402+
// create new browser window object with size, title, security options
403403
const tutorial = new BrowserWindow({
404404
width: 800,
405405
height: 600,
@@ -439,4 +439,4 @@ ipcMain.on('tutorial', event => {
439439

440440

441441

442-
//module.exports = dialog;
442+
//module.exports = dialog;

app/src/components/left/HTMLItem.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ItemTypes } from '../../constants/ItemTypes';
44
import Grid from '@material-ui/core/Grid';
55
import { makeStyles } from '@material-ui/core/styles';
66

7+
const buttonClasses =
8+
'MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-button-12 MuiButton-textPrimary';
79

810
const useStyles = makeStyles({
911
HTMLPanelItem: {
@@ -29,7 +31,8 @@ const HTMLItem: React.FC<{
2931
name: string;
3032
id: number;
3133
Icon: any;
32-
}> = ({ name, id, Icon }) => {
34+
handleDelete: (id: number) => void;
35+
}> = ({ name, id, Icon, handleDelete }) => {
3336
const classes = useStyles();
3437

3538
const [{ isDragging }, drag] = useDrag({
@@ -58,6 +61,7 @@ const HTMLItem: React.FC<{
5861
>
5962
{Icon && <Icon />}
6063
</span>
64+
<button className={buttonClasses} onClick={() => { handleDelete(id) }} > X </button>
6165
</div>
6266
</Grid>
6367
);

app/src/components/left/HTMLPanel.tsx

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const HTMLPanel = (): JSX.Element => {
2727
setName(e.target.value);
2828
};
2929

30-
const checkNameDupe = (inputName: String) => {
30+
const checkNameDupe = (inputName: String): boolean => {
3131
let checkList = state.HTMLTypes.slice();
3232

3333
// checks to see if inputted comp name already exists
@@ -66,6 +66,8 @@ const HTMLPanel = (): JSX.Element => {
6666
const formattedName =
6767
inputNameClean.charAt(0).toUpperCase() + inputNameClean.slice(1);
6868
// add new component to state
69+
console.log(inputTag);
70+
console.log(inputName);
6971
const newElement = {
7072
id: currentID,
7173
tag: inputTag,
@@ -79,13 +81,19 @@ const HTMLPanel = (): JSX.Element => {
7981
type: 'ADD ELEMENT',
8082
payload: newElement
8183
});
82-
const nextID = currentID + 1;
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;
8391
setCurrentID(nextID);
8492
setTag('');
8593
setName('');
8694
};
8795

88-
const alphanumeric = input => {
96+
const alphanumeric = (input:string): boolean => {
8997
let letterNumber = /^[0-9a-zA-Z]+$/;
9098
if (input.match(letterNumber)) return true;
9199
return false;
@@ -111,6 +119,13 @@ const HTMLPanel = (): JSX.Element => {
111119
resetError();
112120
};
113121

122+
const handleDelete = (id: number): void => {
123+
dispatch({
124+
type: "DELETE ELEMENT",
125+
payload: id
126+
});
127+
}
128+
114129
return (
115130
<div>
116131
<h4> HTML Elements</h4>
@@ -167,6 +182,7 @@ const HTMLPanel = (): JSX.Element => {
167182
key={`html-${option.name}`}
168183
id={option.id}
169184
Icon={option.icon}
185+
handleDelete={handleDelete}
170186
/>
171187
))}
172188
</Grid>
@@ -175,9 +191,6 @@ const HTMLPanel = (): JSX.Element => {
175191
};
176192

177193
const useStyles = makeStyles({
178-
inputField: {
179-
marginTop: '15px'
180-
},
181194
inputWrapper: {
182195
// height: '115px',
183196
textAlign: 'center',
@@ -192,25 +205,6 @@ const useStyles = makeStyles({
192205
padding: '20px',
193206
margin: '20px'
194207
},
195-
rootCheckBox: {},
196-
rootCheckBoxLabel: {
197-
color: 'white'
198-
},
199-
panelWrapper: {
200-
width: '100%',
201-
marginTop: '15px'
202-
},
203-
panelWrapperList: {
204-
// maxHeight: '400px',
205-
minHeight: '120px',
206-
// overflowY: 'auto',
207-
marginLeft: '-15px',
208-
marginRight: '-15px'
209-
},
210-
panelSubheader: {
211-
textAlign: 'center',
212-
color: '#fff'
213-
},
214208
input: {
215209
color: '#fff',
216210
borderRadius: '5px',
@@ -228,24 +222,6 @@ const useStyles = makeStyles({
228222
zIndex: 20,
229223
color: '#fff',
230224
marginTop: '-10px'
231-
},
232-
btnGroup: {
233-
display: 'flex',
234-
flexDirection: 'column',
235-
paddingTop: '10px',
236-
marginLeft: '10px'
237-
},
238-
button: {
239-
fontSize: '1rem',
240-
height: '40px',
241-
maginTop: '10px',
242-
width: '100%',
243-
// border: '1px solid rgba(70,131,83)',
244-
backgroundColor: 'rgba(1,212,109,0.1)'
245-
},
246-
rootToggle: {
247-
color: '#01d46d',
248-
fontSize: '0.85rem'
249225
}
250226
});
251227

app/src/containers/AppContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { theme1 } from '../public/styles/theme';
88
import { makeStyles } from '@material-ui/core/styles';
99

1010
export const styleContext = createContext({
11-
style: null,
11+
style: null,
1212
setStyle: null
1313
});
1414
// console.log('styleContext: ', styleContext);

app/src/helperFunctions/generateCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const generateUnformattedCode = (
161161
}
162162
${
163163
stateful && !classBased
164-
? `const [value, setValue] = useState("INITIAL VALUE");`
164+
? `const [value, setValue] = useState<any | undefined>("INITIAL VALUE");`
165165
: ``
166166
}
167167
${
@@ -195,7 +195,7 @@ const generateUnformattedCode = (
195195
196196
const ${currentComponent.name} = (props): JSX.Element => {
197197
198-
const [value, setValue] = useState("INITIAL VALUE");
198+
const [value, setValue] = useState<any | undefined>("INITIAL VALUE");
199199
200200
return (
201201
<>

app/src/index.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,8 @@ import Cookies from 'js-cookie';
77
import SignIn from './components/login/SignIn.tsx';
88
import SignUp from './components/login/SignUp.tsx';
99
import Tutorial from './tutorial/Tutorial.tsx';
10-
import Pages from './tutorial/Pages.tsx';
11-
import Customization from './tutorial/Customization.tsx';
12-
import Canvas from './tutorial/Canvas.tsx';
13-
import Styling from './tutorial/Styling.tsx';
14-
import RouteLinks from './tutorial/RouteLinks.tsx';
15-
import ReusableComponents from './tutorial/ReusableComponents.tsx';
16-
import ComponentTree from './tutorial/ComponentTree.tsx';
17-
import HtmlElements from './tutorial/HtmlElements.tsx';
18-
import CodePreview from './tutorial/CodePreview.tsx';
10+
import TutorialPage from './tutorial/TutorialPage.tsx';
11+
1912

2013
import {
2114
HashRouter as Router,
@@ -24,6 +17,7 @@ import {
2417
Switch,
2518
} from 'react-router-dom';
2619

20+
2721
const PrivateRoute = ({ component: Component, ...rest }) => (
2822
<Route
2923
{...rest}
@@ -45,16 +39,8 @@ ReactDOM.render(
4539
<Route exact path="/signup" component={SignUp} />
4640
<PrivateRoute exact path="/" component={App} />
4741
<Route exact path="/tutorial" component={Tutorial}/>
48-
<Route exact path="/pages" component={Pages}/>
49-
<Route exact path="/links" component={RouteLinks}/>
50-
<Route exact path="/code-preview" component={CodePreview}/>
51-
<Route exact path="/reusable-components" component={ReusableComponents}/>
52-
<Route exact path="/component-tree" component={ComponentTree}/>
53-
<Route exact path="/html-elements" component={HtmlElements}/>
54-
<Route exact path="/styling" component={Styling}/>
55-
<Route exact path="/customization" component={Customization}/>
56-
<Route exact path="/canvas" component={Canvas}/>
42+
<Route exact path="/tutorialPage/:learn" component={TutorialPage} value={'test'} />
5743
</Switch>
5844
</Router>,
5945
document.getElementById('app')
60-
);
46+
);

0 commit comments

Comments
 (0)