Skip to content

Commit 93b0d74

Browse files
authored
Merge pull request #33 from gspletzer/preload
GraphQL Controller refactor
2 parents 27bb4a7 + 14ac8ea commit 93b0d74

File tree

6 files changed

+44
-57
lines changed

6 files changed

+44
-57
lines changed

package-lock.json

Lines changed: 25 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

preload.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ contextBridge.exposeInMainWorld("api", {
88
"confirm-clear-history",
99
"import-proto",
1010
"quit-and-install",
11+
"open-gql",
12+
"import-collection",
13+
"export-collection",
1114
'open-http',
1215
];
1316
if (allowedChannels.includes(channel)) {
@@ -23,6 +26,7 @@ contextBridge.exposeInMainWorld("api", {
2326
"clear-history-response",
2427
"proto-info",
2528
"message",
29+
"reply-gql",
2630
'reqResUpdate'
2731
];
2832
if (allowedChannels.includes(channel)) {

src/client/components/containers/ContentsContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React, { Component } from "react";
22

33
// import GraphContainer from './GraphContainer.jsx';
44
import ReqResContainer from './ReqResContainer.jsx';

src/client/components/containers/UpdatePopUpContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class UpdatePopUpContainer extends Component {
4040
<p>{this.state.message}</p>
4141
{this.state.message === "Update downloaded." && (
4242
<>
43-
<p class="updateMessage">
43+
<p className="updateMessage">
4444
Do you want to restart and install now? <br /> (If not, will
4545
auto-install on restart.)
4646
</p>

src/client/controllers/collectionsController.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import db from "../db";
44
import * as store from "../store";
55
import * as actions from "../actions/actions";
66

7-
const { api } = window;
7+
const { api } = window;
88

9-
10-
api.receive('add-collection', (...args) => {
11-
console.log('received data: ', JSON.parse(args.data));
12-
collectionsController.addCollectionToIndexedDb(JSON.parse(args.data));
13-
collectionsController.getCollections();
9+
api.receive("add-collection", (...args) => {
10+
console.log("received data: ", JSON.parse(args.data));
11+
collectionsController.addCollectionToIndexedDb(JSON.parse(args.data));
12+
collectionsController.getCollections();
1413
});
1514

1615
const collectionsController = {
@@ -63,7 +62,7 @@ const collectionsController = {
6362
foundCollection.name += " import";
6463
foundCollection.id = uuid();
6564

66-
ipcRenderer.send("export-collection", { collection: foundCollection });
65+
api.send("export-collection", { collection: foundCollection });
6766
})
6867
.catch((error) => {
6968
console.error(error.stack || error);
@@ -72,7 +71,7 @@ const collectionsController = {
7271
},
7372

7473
importCollection(collection) {
75-
ipcRenderer.send("import-collection", collection);
74+
api.send("import-collection", collection);
7675
},
7776
};
7877

src/client/controllers/graphQLController.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { InMemoryCache } from "apollo-cache-inmemory";
44
import { WebSocketLink } from "apollo-link-ws";
55
import { SubscriptionClient } from "subscriptions-transport-ws";
66
//const { session } = require('electron').remote
7-
const { ipcRenderer } = require("electron");
7+
const { api } = window;
88

99
import * as store from "../store";
1010
import * as actions from "../actions/actions";
@@ -26,17 +26,19 @@ const graphQLController = {
2626
});
2727
},
2828

29-
// handles graphQL queries and mutations
29+
// handles graphQL queries and mutationsnp
3030
sendGqlToMain(args) {
3131
return new Promise((resolve) => {
32-
ipcRenderer.send("open-gql", args);
33-
ipcRenderer.on("reply-gql", (event, result) => {
32+
api.receive("reply-gql", (result) => {
33+
console.log("This is result:", result);
3434
// needs formatting because component reads them in a particular order
3535
result.reqResObj.response.cookies = this.cookieFormatter(
3636
result.reqResObj.response.cookies
3737
);
38+
console.log(result);
3839
resolve(result);
3940
});
41+
api.send("open-gql", args);
4042
});
4143
},
4244

0 commit comments

Comments
 (0)