Skip to content

Commit ae2e7be

Browse files
committed
changes
1 parent c57224f commit ae2e7be

5 files changed

Lines changed: 45 additions & 29 deletions

File tree

app/context/ApplicationContext.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,20 @@ const ApplicationContextProvider: React.FC = ({ children }) => {
1919
/**
2020
* Connect to database provided by user at 'index'
2121
*/
22-
const connectToDB = async (index: number) => {
22+
const connectToDB = async (index: number, application: string) => {
2323
await ipcRenderer.send('connect', index);
24+
console.log(`${__dirname}/ApplicationContext.tsx/connectToDB: ** between connect & servicesRequest`);
25+
26+
// Response
27+
ipcRenderer.on('databaseConnected', (event: Electron.Event, data: any) => {
28+
// Parse JSON response
29+
const result = data;
30+
if (result.length)
31+
console.log(`${__dirname}/ApplicationContext.tsx/connectToDB: ${result}`);
32+
33+
fetchServicesNames(application);
34+
});
35+
2436
};
2537

2638
/**

app/modals/ServicesModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const ServicesModal: React.SFC<ServicesModalProps> = ({ i, app }) => {
1919
);
2020

2121
useEffect(() => {
22-
connectToDB(i);
23-
fetchServicesNames(app);
22+
connectToDB(i, app);
23+
// fetchServicesNames(app);
2424

2525
return () => {
2626
setServicesData([]);

electron/databases/mongo.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ import mongoose from 'mongoose';
22
import { MongoError } from 'mongodb';
33

44
// Mongoose connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
5-
const connectMongoose = (i: number, URI: string) => {
6-
return mongoose.connect(
7-
URI,
8-
{ useNewUrlParser: true, useUnifiedTopology: true },
9-
(err: MongoError) => {
10-
if (err) console.log(err);
11-
console.log('Connected to Mongo database!');
12-
}
13-
);
5+
const connectMongoose = async (i: number, URI: string) => {
6+
try {
7+
const db = await mongoose.connect(
8+
URI,
9+
{ useNewUrlParser: true, useUnifiedTopology: true }
10+
// ,
11+
// (err: MongoError) => {
12+
// if (err) console.log(err);
13+
// console.log('Connected to Mongo database!');
14+
// }
15+
);
16+
console.log(`${__dirname}/mongo.ts/connectMongoose: connected!`);
17+
return db;
18+
} catch(err) {
19+
console.log(`${__dirname}/mongo.ts/connectMongoose: ${err}`);
20+
}
1421
};
1522
export default connectMongoose;

electron/routes/data.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let currentDatabaseType: string;
2121
*/
2222
ipcMain.on('connect', async (message: Electron.IpcMainEvent, index: number) => {
2323
try {
24-
console.log('Attempting to connect to DB');
24+
console.log('electron/routes/data.ts, ipcMain.on(connect): 1 Attempting to connect to DB');
2525
// Extract databaseType and URI from settings.json at particular index
2626
// get index from application context
2727
const fileContents = fs.readFileSync(path.resolve(__dirname, '../user/settings.json'), 'utf8');
@@ -30,14 +30,18 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, index: number) => {
3030
// We get index from sidebar container: which is the mapplication (DEMO)
3131
const [databaseType, URI] = [userDatabase[1], userDatabase[2]];
3232

33+
console.log('electron/routes/data.ts, ipcMain.on(connect): 2 pre-connect');
34+
3335
// Connect to the proper database
3436
if (databaseType === 'MongoDB') await connectMongo(index, URI);
3537
if (databaseType === 'SQL') pool = await connectPostgres(index, URI);
3638

37-
console.log('connected?');
39+
console.log('electron/routes/data.ts, ipcMain.on(connect): 3 connected');
3840

3941
// Currently set to a global variable
4042
currentDatabaseType = databaseType;
43+
44+
message.sender.send('databaseConnected', 'connected!');
4145
} catch ({ message }) {
4246
console.log('Error in "connect" event', message);
4347
}
@@ -49,7 +53,7 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, index: number) => {
4953
*/
5054
ipcMain.on('servicesRequest', async (message: Electron.IpcMainEvent) => {
5155
try {
52-
console.log('Requesting application microservices');
56+
console.log('electron/routes/data.ts, ipcMain.on(servicesRequest): 4 Requesting application microservices');
5357
let result: any;
5458

5559
// Mongo Database

electron/user/settings.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
{
22
"setupRequired": false,
33
"services": [
4-
[
5-
"myPostgres",
6-
"SQL",
7-
"postgres://zwezmnqm:8onRNKC9MzktDeL3NpI_8Q62UfLLM3UK@ruby.db.elephantsql.com:5432/zwezmnqm",
8-
"Online bookstore with that keeps track of orders and customers",
9-
"Jun 28, 2020 4:58 PM"
10-
],
11-
[
12-
"myMongo",
13-
"MongoDB",
14-
"mongodb+srv://chronos:pass123@cluster0-xluio.mongodb.net/chronos?retryWrites=true&w=majority",
15-
"E-commerce website for buying and selling clothes",
16-
"Jul 01, 2020 10:33 PM"
17-
],
184
[
195
"ToddDB",
206
"MongoDB",
217
"mongodb+srv://tdwolf6:password16@cluster0-0xvd7.gcp.mongodb.net/Chronos?retryWrites=true&w=majority",
228
"Web app deployed on AWS",
239
"Jul 3, 2020 7:12AM"
10+
],
11+
[
12+
"myPostgres",
13+
"SQL",
14+
"postgres://zwezmnqm:8onRNKC9MzktDeL3NpI_8Q62UfLLM3UK@ruby.db.elephantsql.com:5432/zwezmnqm",
15+
"Online bookstore with that keeps track of orders and customers",
16+
"Jun 28, 2020 4:58 PM"
2417
]
2518
],
2619
"splash": true

0 commit comments

Comments
 (0)