Skip to content

Commit 41125e7

Browse files
committed
started on oauth
2 parents d097a5c + 3359154 commit 41125e7

File tree

13 files changed

+166
-118
lines changed

13 files changed

+166
-118
lines changed

app/electron/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ ipcMain.on('delete_cookie', event => {
362362

363363
// opens new window for github oauth when button on signin page is clicked
364364
ipcMain.on('github', event => {
365+
// your github applications credentials
366+
const options = {
367+
client_id: 'your_client_id',
368+
client_secret: 'your_client_secret',
369+
scopes: ['user:email', 'notifications']
370+
};
365371
// create new browserwindow object with size, title, security options
366372
const github = new BrowserWindow({
367373
width: 800,
@@ -376,8 +382,11 @@ ipcMain.on('github', event => {
376382
zoomFactor: 1.0
377383
}
378384
});
385+
const githubUrl = 'https://github.com/login/oauth/authorize?';
386+
const authUrl =
387+
githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
379388
// redirects to relevant server endpoint
380-
github.loadURL(`${serverUrl}/github`);
389+
github.loadURL(authUrl);
381390
// show window
382391
github.show();
383392
// if final callback is reached and we get a redirect from server back to our app, close oauth window

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/components/login/SignIn.tsx

Lines changed: 2 additions & 0 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 (
@@ -228,6 +229,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
228229
// messages the main proces to open new window for github oauth
229230
console.log('open github');
230231
console.log(window.api);
232+
// ipcRenderer.send('github-oauth', 'getToken');
231233
window.api.github();
232234
}}
233235
>

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+
);

app/src/reducers/componentReducer.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ const reducer = (state: State, action: Action) => {
9191
const updateIds = (components: Component[]) => {
9292
// component IDs should be array index + 1
9393
components.forEach((comp, i) => (comp.id = i + 1));
94-
95-
// create KV pairs of component names and corresponding IDs
94+
95+
// create KV pairs of component names and corresponding IDs
9696
const componentIds = {};
9797
components.forEach(component => {
9898
if (!component.isPage ) componentIds[component.name] = component.id;
@@ -102,7 +102,7 @@ const reducer = (state: State, action: Action) => {
102102
components.forEach(page => {
103103
if (page.isPage) {
104104
page.children.forEach(child => {
105-
if (child.type === 'Component') child.typeId = componentIds[child.name];
105+
if (child.type === 'Component') child.typeId = componentIds[child.name];
106106
});
107107
}
108108
});
@@ -137,7 +137,7 @@ const reducer = (state: State, action: Action) => {
137137
arr.splice(i, 1);
138138
}
139139
})
140-
}
140+
}
141141
searchNestedComps(childComponents.children)
142142
});
143143
}
@@ -152,9 +152,8 @@ const reducer = (state: State, action: Action) => {
152152
action.payload.componentName === ''
153153
)
154154
return state;
155-
155+
156156
const components = [...state.components];
157-
console.log('adding =>', action.payload.componentName);
158157
const newComponent = {
159158
id: state.components.length + 1,
160159
name: action.payload.componentName,
@@ -211,20 +210,20 @@ const reducer = (state: State, action: Action) => {
211210
}
212211
});
213212
}
214-
213+
215214
if (type === 'Component') {
216215
const originalComponent = findComponent(state.components, typeId);
217216
if (childTypeExists('Component', parentComponentId, originalComponent))
218217
return state;
219218
}
220-
219+
221220
let newName = state.HTMLTypes.reduce((name, el) => {
222221
if (typeId === el.id) {
223222
name = (type === 'Component') ? componentName : el.tag;
224223
}
225224
return name;
226225
}, '');
227-
226+
228227
if (type === 'Route Link') {
229228
components.find(comp => {
230229
if (comp.id === typeId) {
@@ -345,7 +344,7 @@ const reducer = (state: State, action: Action) => {
345344
}
346345
case 'DELETE CHILD': {
347346
// if in-focus instance is a top-level component and not a child, don't delete anything
348-
347+
349348
if (!state.canvasFocus.childId) return state;
350349

351350
// find the current component in focus
@@ -477,7 +476,9 @@ const reducer = (state: State, action: Action) => {
477476
}
478477

479478
case 'OPEN PROJECT': {
479+
console.log("BEFORE: ", action.payload.HTMLTypes);
480480
convertToJSX(action.payload.HTMLTypes);
481+
console.log("AFTER: ", action.payload.HTMLTypes);
481482
return {
482483
...action.payload
483484
};
@@ -491,6 +492,20 @@ const reducer = (state: State, action: Action) => {
491492
HTMLTypes
492493
};
493494
}
495+
496+
case 'DELETE ELEMENT': {
497+
const HTMLTypes = [...state.HTMLTypes];
498+
for (let i = 0; i < HTMLTypes.length; i+=1) {
499+
if (HTMLTypes[i].id === action.payload) {
500+
HTMLTypes.splice(i, 1);
501+
}
502+
}
503+
return {
504+
...state,
505+
HTMLTypes
506+
}
507+
}
508+
494509
default:
495510
return state;
496511
}

0 commit comments

Comments
 (0)