Skip to content

Commit e268d1f

Browse files
committed
graphQL controller refactored for preload.js
1 parent 95617c7 commit e268d1f

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

preload.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ const { ipcRenderer, contextBridge } = require("electron");
22

33
contextBridge.exposeInMainWorld("api", {
44
send: (channel, data) => {
5+
console.log("inside send", channel);
56
// allowlist channels
67
const allowedChannels = [
78
"toMain",
89
"confirm-clear-history",
910
"import-proto",
1011
"quit-and-install",
12+
"open-gql",
13+
"import-collection",
14+
"export-collection",
1115
];
1216
if (allowedChannels.includes(channel)) {
1317
ipcRenderer.send(channel, data);
@@ -22,6 +26,7 @@ contextBridge.exposeInMainWorld("api", {
2226
"clear-history-response",
2327
"proto-info",
2428
"message",
29+
"reply-gql",
2530
];
2631
if (allowedChannels.includes(channel)) {
2732
ipcRenderer.on(channel, (event, ...args) => cb(...args));

src/client/components/containers/App.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { Component } from "react";
22
import "../../../assets/style/App.scss";
33
const { api } = window;
4-
// import ContentsContainer from './ContentsContainer.jsx';
5-
// import ReqResCtrl from '../../controllers/reqResController';
4+
import ContentsContainer from "./ContentsContainer.jsx";
5+
import ReqResCtrl from "../../controllers/reqResController";
66
import SidebarContainer from "./SidebarContainer.jsx";
77
import UpdatePopUpContainer from "./UpdatePopUpContainer.jsx";
88
import historyController from "../../controllers/historyController";
@@ -56,7 +56,7 @@ class App extends Component {
5656
<div id="app">
5757
<UpdatePopUpContainer />
5858
<SidebarContainer />
59-
{/* <ContentsContainer /> */}
59+
<ContentsContainer />
6060
</div>
6161
);
6262
}

src/client/components/containers/ContentsContainer.jsx

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

33
import GraphContainer from './GraphContainer.jsx';
4-
import ReqResContainer from './ReqResContainer.jsx';
4+
import ReqResContainer from "./ReqResContainer.jsx";
55
import NavBarContainer from './NavBarContainer.jsx';
66

77
class Contents extends Component {
@@ -10,11 +10,11 @@ class Contents extends Component {
1010
}
1111

1212
render() {
13-
return(
14-
<div className={'contents'}>
15-
<GraphContainer/>
16-
<NavBarContainer/>
17-
<ReqResContainer/>
13+
return (
14+
<div className={"contents"}>
15+
<GraphContainer />
16+
<NavBarContainer />
17+
<ReqResContainer />
1818
</div>
1919
);
2020
}

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)