Skip to content

Commit 18a4b55

Browse files
Merge pull request #2 from slhoehn/router
create dashboard to test graphQL's communication with database
2 parents 53ededf + 5bb9a2e commit 18a4b55

File tree

17 files changed

+365
-118
lines changed

17 files changed

+365
-118
lines changed

app/electron/main.js

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
2+
const electron = require('electron');
3+
14
/*
25
@description: main.js is what controls the lifecycle of the electron application from initialization to termination.
3-
@actions: codes for Github Oauth has been commented out because of lack of functionality.
6+
@actions: codes for Github Oauth has been commented out because of lack of functionality.
47
*/
58
require('dotenv').config();
69
const path = require('path');
@@ -13,14 +16,16 @@ const {
1316
ipcMain,
1417
} = require('electron');
1518

19+
20+
1621
// The splash screen is what appears while the app is loading
1722
const { initSplashScreen, OfficeTemplate } = require('electron-splashscreen');
1823
const { resolve } = require('app-root-path');
1924

2025
// to install react dev tool extension
2126
const {
2227
default: installExtension,
23-
REACT_DEVELOPER_TOOLS
28+
REACT_DEVELOPER_TOOLS,
2429
} = require('electron-devtools-installer');
2530
const debug = require('electron-debug');
2631

@@ -30,8 +35,7 @@ const Protocol = require('./protocol');
3035
const MenuBuilder = require('./menu');
3136

3237
// mode that the app is running in
33-
const isDev =
34-
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
38+
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
3539
const port = 8080;
3640
const selfHost = `http://localhost:${port}`;
3741

@@ -56,11 +60,13 @@ async function createWindow() {
5660
// Create the browser window.
5761
win = new BrowserWindow({
5862
// full screen
59-
width: 1920,
60-
height: 1080,
63+
// width: 1920,
64+
// height: 1080,
65+
width: 1024,
66+
height: 576,
6167
minWidth: 980,
6268
// window title
63-
title: `ReacType`,
69+
title: 'ReacType',
6470
// the browser window will not display initially as it's loading
6571
// once the browser window renders, a function is called below that hides the splash screen and displays the browser window
6672
show: false,
@@ -83,8 +89,8 @@ async function createWindow() {
8389
enableRemoteModule: false,
8490
// path of preload script. preload is how the renderer page will have access to electron functionality
8591
preload: path.join(__dirname, 'preload.js'),
86-
nativeWindowOpen: true
87-
}
92+
nativeWindowOpen: true,
93+
},
8894
});
8995

9096
// Splash screen that appears while loading
@@ -99,7 +105,7 @@ async function createWindow() {
99105
logo: resolve('app/src/public/icons/png/64x64.png'),
100106
color: '#3BBCAF',
101107
website: 'www.reactype.io',
102-
text: 'Initializing ...'
108+
text: 'Initializing ...',
103109
});
104110

105111
// Load app
@@ -122,7 +128,7 @@ async function createWindow() {
122128
if (isDev) {
123129
win.webContents.once('dom-ready', () => {
124130
debug();
125-
//win.webContents.openDevTools();
131+
win.webContents.openDevTools();
126132
});
127133
}
128134

@@ -147,13 +153,13 @@ async function createWindow() {
147153
ses
148154
.fromPartition(partition)
149155
.setPermissionRequestHandler((webContents, permission, callback) => {
150-
let allowedPermissions = []; // Full list here: https://developer.chrome.com/extensions/declare_permissions#manifest
156+
const allowedPermissions = []; // Full list here: https://developer.chrome.com/extensions/declare_permissions#manifest
151157

152158
if (allowedPermissions.includes(permission)) {
153159
callback(true); // Approve permission request
154160
} else {
155161
console.error(
156-
`The application tried to request permission for '${permission}'. This permission was not whitelisted and has been blocked.`
162+
`The application tried to request permission for '${permission}'. This permission was not whitelisted and has been blocked.`,
157163
);
158164

159165
callback(false); // Deny
@@ -165,10 +171,10 @@ async function createWindow() {
165171
// we could use this over _all_ urls
166172
ses
167173
.fromPartition(partition)
168-
.webRequest.onBeforeRequest({ urls: ['http://localhost./*'] }, listener => {
174+
.webRequest.onBeforeRequest({ urls: ['http://localhost./*'] }, (listener) => {
169175
if (listener.url.indexOf('http://') >= 0) {
170176
listener.callback({
171-
cancel: true
177+
cancel: true,
172178
});
173179
}
174180
});
@@ -185,16 +191,27 @@ protocol.registerSchemesAsPrivileged([
185191
standard: true,
186192
secure: true,
187193
allowServiceWorkers: true,
188-
supportFetchAPI: true
189-
}
190-
}
194+
supportFetchAPI: true,
195+
},
196+
},
191197
]);
192198

193199
// This method will be called when Electron has finished
194200
// initialization and is ready to create browser windows.
195201
// Some APIs can only be used after this event occurs.
196202
app.on('ready', createWindow);
197203

204+
// TRYING ELECTRON-WINDOW-MANAGER When the application is ready
205+
206+
// app.on('ready', () => {
207+
// windowManager.setDefaultSetup({'width': 800, 'height': 450, 'position': 'right'});
208+
// // Open Dashboard window
209+
// const dashboard = windowManager.open('home', 'Welcome ...', 'http://localhost:5000/home.html');
210+
// dashboard.toggleDevTools(false);
211+
// // Load ReacType window
212+
// createWindow();
213+
// });
214+
198215
// Quit when all windows are closed.
199216
app.on('window-all-closed', () => {
200217
app.quit();
@@ -223,16 +240,15 @@ app.on('web-contents-created', (event, contents) => {
223240
'https://www.facebook.com',
224241
'https://developer.mozilla.org',
225242
'https://www.smashingmagazine.com',
226-
'https://www.html5rocks.com'
243+
'https://www.html5rocks.com',
227244
];
228245
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
229246
if (!validOrigins.includes(parsedUrl.origin)) {
230247
console.error(
231-
`The application tried to navigate to the following address: '${parsedUrl}'. This origin is not whitelisted attempt to navigate was blocked.`
248+
`The application tried to navigate to the following address: '${parsedUrl}'. This origin is not whitelisted attempt to navigate was blocked.`,
232249
);
233250
// if the requested URL is not in the whitelisted array, then don't navigate there
234251
event.preventDefault();
235-
return;
236252
}
237253
});
238254

@@ -247,20 +263,19 @@ app.on('web-contents-created', (event, contents) => {
247263
'https://developer.mozilla.org',
248264
'https://www.facebook.com',
249265
'https://www.smashingmagazine.com',
250-
'https://www.html5rocks.com'
266+
'https://www.html5rocks.com',
251267
];
252268

253269
// Log and prevent the app from redirecting to a new page
254270
if (
255-
!validOrigins.includes(parsedUrl.origin) &&
256-
!validOrigins.includes(parsedUrl.href)
271+
!validOrigins.includes(parsedUrl.origin)
272+
&& !validOrigins.includes(parsedUrl.href)
257273
) {
258274
console.error(
259-
`The application tried to redirect to the following address: '${navigationUrl}'. This attempt was blocked.`
275+
`The application tried to redirect to the following address: '${navigationUrl}'. This attempt was blocked.`,
260276
);
261277

262278
event.preventDefault();
263-
return;
264279
}
265280
});
266281

@@ -290,16 +305,15 @@ app.on('web-contents-created', (event, contents) => {
290305
'https://github.com',
291306
'https://www.facebook.com',
292307
'https://www.smashingmagazine.com',
293-
'https://www.html5rocks.com'
308+
'https://www.html5rocks.com',
294309
];
295310
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
296311
if (!validOrigins.includes(parsedUrl.origin)) {
297312
console.error(
298-
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`
313+
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`,
299314
);
300315
// if the requested URL is not in the whitelisted array, then don't navigate there
301316
event.preventDefault();
302-
return;
303317
}
304318
});
305319
});
@@ -331,15 +345,15 @@ app.on('remote-get-current-web-contents', (event, webContents) => {
331345
// When a user selects "Export project", a function (chooseAppDir loaded via preload.js)
332346
// is triggered that sends a "choose_app_dir" message to the main process
333347
// when the "choose_app_dir" message is received it triggers this event listener
334-
ipcMain.on('choose_app_dir', event => {
348+
ipcMain.on('choose_app_dir', (event) => {
335349
// dialog displays the native system's dialogue for selecting files
336350
// once a directory is chosen send a message back to the renderer with the path of the directory
337351
dialog
338352
.showOpenDialog(win, {
339353
properties: ['openDirectory'],
340-
buttonLabel: 'Export'
354+
buttonLabel: 'Export',
341355
})
342-
.then(directory => {
356+
.then((directory) => {
343357
if (!directory) return;
344358
event.sender.send('app_dir_selected', directory.filePaths[0]);
345359
})

app/electron/render.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
var remote = require('remote');
3+
var windowManager = remote.require('electron-window-manager');
4+
5+
// Create a new window
6+
var win2 = windowManager.createNew('win2', 'Windows #2');
7+
win2.setURL('/win2.html');
8+
win2.onReady( ... );
9+
win2.open();
10+
</script>

app/src/Dashboard/Form.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
import React from 'react';
3+
4+
5+
const Form = (props) => {
6+
return (
7+
<div className = 'form'>
8+
<h2>{ props.description }</h2>
9+
<button id={ props.id }>heart</button>
10+
</div>);
11+
};
12+
13+
export default Form;

app/src/Dashboard/FormsContainer.jsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
4+
import { gql, useQuery } from '@apollo/client';
5+
import Form from './Form.jsx';
6+
7+
// Implement Apollo Client useQuery hook to retrieve data from the server through graphQL. This includes 2 steps:
8+
// 1) Impliment Apollo Provider in the top component in ./src/index.js, this allows children components access to the queried data
9+
// 2) useQuery hook will update the data stored in Apollo Client's cache and automatically trigger child components rendering
10+
11+
const FormsContainer = () => {
12+
// define the graphQL query string
13+
const GET_TESTS = gql`query {readAllTests { description id }}`;
14+
// useQuery hook abstracts fetch request
15+
const { loading, error, data } = useQuery(GET_TESTS);
16+
if (loading) return <p>Loading...</p>;
17+
if (error) return <p>Error :{error}</p>;
18+
// based on resolver(readAllTests) for this query, the data is stored in the data object with the key 'readAllTests'
19+
const myTests = data.readAllTests;
20+
// generate an array of Form components based on data
21+
const forms = myTests.map((test, index) => <Form key={index} id={test.id} description={test.description} />);
22+
23+
return (
24+
<div>
25+
<Link to="/">
26+
<button type="button">Go Back</button>
27+
</Link>
28+
{forms}
29+
</div>
30+
);
31+
};
32+
33+
export default FormsContainer;

app/src/Dashboard/styles.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* @import url('https://fonts.googleapis.com/css2?family=Cabin&family=Oswald&display=swap');
2+
3+
4+
$primary-black: #22292f;
5+
$secondary-black: #606f7b;
6+
$teriary-grey: #f0f0f0;
7+
$light-grey: #bfcbd4;
8+
$light-blue: #759cc9;
9+
$button-blue: #24BCFF; */
10+
11+
.form {
12+
display: flex;
13+
flex-direction: column;
14+
background-color: white;
15+
border: 1px solid #f0f0f0;
16+
box-shadow: 0 0 5px rgba(0,0,0,0.3);
17+
margin: 5px;
18+
border-radius: 5px;
19+
color: #606f7b;
20+
align-items: center;
21+
height: 300px;
22+
justify-content: min;
23+
width: 250px;
24+
}
25+

app/src/components/top/NavBar.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ import createModal from '../right/createModal';
2828
import StateContext from '../../context/context';
2929
import logo from '../../public/icons/win/logo.png';
3030

31+
32+
33+
// ROUTING TO DASHBOARD
34+
import { Link } from "react-router-dom";
35+
36+
37+
38+
3139
// NavBar text and button styling
3240
const useStyles = makeStyles((theme: Theme) =>
3341
createStyles({
@@ -158,6 +166,21 @@ export default function NavBar(props) {
158166
<Typography variant="h6" style={{marginLeft: '1rem'}} className={classes.title}>
159167
ReacType
160168
</Typography>
169+
170+
{/* ==================================Dashboard Button================================================== */}
171+
<Link to='/dashboard'>
172+
<Button
173+
variant="contained"
174+
color="primary"
175+
style={{minWidth: '137.69px'}}
176+
className="navbarButton"
177+
id="navbarButton1"
178+
>
179+
Dashboard
180+
</Button>
181+
</Link>
182+
{/* ==================================Dashboard Button================================================== */}
183+
161184
<Button
162185
variant="contained"
163186
color="primary"

0 commit comments

Comments
 (0)