Skip to content

Commit c1164e1

Browse files
committed
working response panel need to migrate request to main process
1 parent 14fe850 commit c1164e1

File tree

5 files changed

+241
-118
lines changed

5 files changed

+241
-118
lines changed

main_process/main_httpController.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const httpController = {
305305
headersResponse[':status'] = response.status;
306306
const receivedCookie = headersResponse['set-cookie'];
307307
headersResponse.cookies = receivedCookie;
308-
308+
console.log(receivedCookie);
309309
const contentType = response.headers.get('content-type');
310310
const contents = /json/.test(contentType)
311311
? await response.json()
@@ -405,7 +405,6 @@ const httpController = {
405405
formattedHeaders.cookie = formattedHeaders.cookie + ';' + cookieString;
406406
});
407407
}
408-
console.log(formattedHeaders);
409408

410409
const outputObj = {
411410
method,

src/client/components/main/TRPC-composer/TRPCComposer.tsx

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useSelector, useDispatch } from 'react-redux';
1010

1111
import trpcController from '../../../controllers/trpcController';
1212
import historyController from '../../../controllers/historyController';
13+
import connectionController from '../../../controllers/reqResController';
1314

1415
// Import MUI components
1516
import { Box } from '@mui/material';
@@ -257,76 +258,12 @@ export default function TRPCComposer(props) {
257258
const sendRequest = async () => {
258259
const id = uuid();
259260

260-
// const headers = newRequest.newRequestHeaders.headersArr.filter(
261-
// (x) => x.active
262-
// );
261+
const headers = newRequest.newRequestHeaders.headersArr.filter(
262+
(x) => x.active
263+
);
263264

264-
// const cookie = cookiesArr.filter((x) => x.active);
265+
const cookie = cookiesArr.filter((x) => x.active);
265266

266-
// const reqRes = {
267-
// id,
268-
// createdAt: new Date(),
269-
// protocol,
270-
// trpc: true,
271-
// url: 'http://localhost:3000/trpc',
272-
// graphQL,
273-
// gRPC,
274-
// webrtc,
275-
// timeSent: null,
276-
// timeReceived: null,
277-
// connection: 'uninitialized',
278-
// connectionType: null,
279-
// checkSelected: false,
280-
// request: {
281-
// method,
282-
// headers,
283-
// procedures,
284-
// bodyType,
285-
// rawType,
286-
// network,
287-
// restUrl,
288-
// wsUrl,
289-
// gqlUrl,
290-
// cookie,
291-
// },
292-
// response: {
293-
// cookies: [],
294-
// headers: {},
295-
// stream: null,
296-
// events: [],
297-
// },
298-
// checked: false,
299-
// minimized: false,
300-
// tab: currentTab,
301-
// };
302-
303-
const cache = [
304-
{
305-
method: 'MUTATE',
306-
endpoint: 'update',
307-
variable: '{\n "userId": "1",\n "name": "nguyen"\n }',
308-
},
309-
{ method: 'QUERY', endpoint: 'sayHi', variable: '' },
310-
{
311-
method: 'MUTATE',
312-
endpoint: 'user.update',
313-
variable: '{\n "userId": "1",\n "name": "justin"\n }',
314-
},
315-
{
316-
method: 'QUERY',
317-
endpoint: 'secretData',
318-
variable: '{\n "userId": "1",\n "name": "justin"\n }',
319-
},
320-
];
321-
322-
const cookiCache = [
323-
{ id: 'cookie0', active: true, key: 'cookie1', value: 'cookie1Val' },
324-
{ id: 'cookie1', active: true, key: 'cookie2', value: 'cookie2Val' },
325-
];
326-
const headerCache = [
327-
{ id: 351217.45631817693, active: true, key: 'auth1', value: 'auth2' },
328-
{ id: 87384.65282544694, active: true, key: 'auth3', value: 'auth4' },
329-
];
330267
const reqRes = {
331268
id,
332269
createdAt: new Date(),
@@ -341,17 +278,18 @@ export default function TRPCComposer(props) {
341278
connection: 'uninitialized',
342279
connectionType: null,
343280
checkSelected: false,
281+
host: 'http://localhost:3000',
344282
request: {
345283
method,
346-
headers: headerCache,
347-
procedures: cache,
284+
headers,
285+
procedures,
348286
bodyType,
349287
rawType,
350288
network,
351289
restUrl,
352290
wsUrl,
353291
gqlUrl,
354-
cookie: cookiCache,
292+
cookie,
355293
},
356294
response: {
357295
cookies: [],
@@ -363,12 +301,84 @@ export default function TRPCComposer(props) {
363301
minimized: false,
364302
tab: currentTab,
365303
};
304+
305+
const cache = [
306+
{
307+
method: 'MUTATE',
308+
endpoint: 'update',
309+
variable: '{\n "userId": "1",\n "name": "nguyen"\n }',
310+
},
311+
{ method: 'QUERY', endpoint: 'sayHi', variable: '' },
312+
{
313+
method: 'MUTATE',
314+
endpoint: 'user.update',
315+
variable: '{\n "userId": "1",\n "name": "justin"\n }',
316+
},
317+
{
318+
method: 'QUERY',
319+
endpoint: 'secretData',
320+
variable: '{\n "userId": "1",\n "name": "justin"\n }',
321+
},
322+
{
323+
method: 'QUERY',
324+
endpoint: 'BLAHBLAH.BLAH',
325+
variable: '{\n "userId": "1",\n "name": "justin"\n }',
326+
},
327+
];
328+
329+
// const cookiCache = [
330+
// { id: 'cookie0', active: true, key: 'cookie1', value: 'cookie1Val' },
331+
// { id: 'cookie1', active: true, key: 'cookie2', value: 'cookie2Val' },
332+
// ];
333+
// const headerCache = [
334+
// { id: 351217.45631817693, active: true, key: 'auth1', value: 'auth2' },
335+
// { id: 87384.65282544694, active: true, key: 'auth3', value: 'auth4' },
336+
// ];
337+
// const reqRes = {
338+
// id,
339+
// createdAt: new Date(),
340+
// protocol,
341+
// trpc: true,
342+
// url: 'http://localhost:3000/trpc',
343+
// graphQL,
344+
// gRPC,
345+
// webrtc,
346+
// timeSent: null,
347+
// timeReceived: null,
348+
// connection: 'uninitialized',
349+
// connectionType: null,
350+
// checkSelected: false,
351+
// host: 'http://localhost:3000',
352+
// request: {
353+
// method,
354+
// headers: headerCache,
355+
// procedures: cache,
356+
// bodyType,
357+
// rawType,
358+
// network,
359+
// restUrl,
360+
// wsUrl,
361+
// gqlUrl,
362+
// cookie: cookiCache,
363+
// },
364+
// response: {
365+
// cookies: [],
366+
// headers: [],
367+
// stream: null,
368+
// events: [],
369+
// },
370+
// checked: false,
371+
// minimized: false,
372+
// tab: currentTab,
373+
// };
366374
// add request to history
367375
historyController.addHistoryToIndexedDb(reqRes);
368376
reqResItemAdded(reqRes);
369377

370378
//reset for next request
371379
// composerFieldsReset();
380+
// connectionController.openReqRes(reqRes.id);
381+
dispatch(responseDataSaved(reqRes));
372382
const updatedReqRes = await trpcController.sendRequest(reqRes);
373383

374384
// const links = [];

src/client/components/main/response-composer/HeadersContainer.tsx

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ interface Props {
1212
}
1313

1414
function HeadersContainer({ currentResponse }: Props) {
15-
const isDark = useSelector((state: { ui: { isDark: boolean } }) => state.ui.isDark);
15+
const isDark = useSelector(
16+
(state: { ui: { isDark: boolean } }) => state.ui.isDark
17+
);
1618

1719
if (
1820
!currentResponse.response ||
@@ -22,17 +24,54 @@ function HeadersContainer({ currentResponse }: Props) {
2224
return <EmptyState />;
2325
}
2426

25-
const responseHeaders = Object.entries(currentResponse.response.headers).map(
26-
([key, value], index) => {
27-
return (
28-
<tr key={index}>
29-
<td>{key}</td>
30-
<td className="table-value">{value}</td>
31-
</tr>
32-
);
33-
}
34-
);
27+
console.log('CURRENT RES ', currentResponse);
28+
let responseHeaders;
3529

30+
{
31+
/* <tbody>{Object.entries(req).map(([key, value], index) => {
32+
return (
33+
<tr key={index}>
34+
<td>{key}</td>
35+
<td className="table-value">{value}</td>
36+
</tr>
37+
);
38+
})}</tbody> */
39+
}
40+
if (currentResponse.trpc) {
41+
responseHeaders = currentResponse.response.headers.map((req, reqMethod) => {
42+
const typeHeader = reqMethod === 0 ? 'QUERY HEADER' : 'MUTATE HEADER';
43+
if (!(Object.keys(req).length === 0)) {
44+
return (
45+
<tbody key={typeHeader} className="is-size-7">
46+
<tr>
47+
<td style={{ color: 'white', backgroundColor: 'rgb(72,84,108)' }}>
48+
{typeHeader}
49+
</td>
50+
</tr>
51+
{Object.entries(req).map(([key, value], index) => {
52+
return (
53+
<tr key={index}>
54+
<td>{key}</td>
55+
<td className="table-value">{value}</td>
56+
</tr>
57+
);
58+
})}
59+
</tbody>
60+
);
61+
}
62+
});
63+
} else {
64+
responseHeaders = Object.entries(currentResponse.response.headers).map(
65+
([key, value], index) => {
66+
return (
67+
<tr key={index}>
68+
<td>{key}</td>
69+
<td className="table-value">{value}</td>
70+
</tr>
71+
);
72+
}
73+
);
74+
}
3675
return (
3776
<div>
3877
<div>
@@ -44,12 +83,12 @@ function HeadersContainer({ currentResponse }: Props) {
4483
<th>Value</th>
4584
</tr>
4685
</thead>
47-
<tbody className="is-size-7">{responseHeaders}</tbody>
86+
{responseHeaders}
4887
</table>
4988
</div>
5089
</div>
5190
</div>
5291
);
5392
}
5493

55-
export default HeadersContainer;
94+
export default HeadersContainer;

src/client/controllers/reqResController.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const connectionController = {
6868
}
6969

7070
if (reqResObj.trpc) {
71-
console.log(reqResObj.request.procedures);
71+
console.log("CAN NOW USE api.receive('reqResUpdate')");
7272
} else if (reqResObj.request.method === 'SUBSCRIPTION')
7373
graphQLController.openSubscription(reqResObj);
7474
else if (reqResObj.graphQL) {
@@ -87,7 +87,6 @@ const connectionController = {
8787
//console.log(reqResObj);
8888
} else {
8989
console.log("we're sending http");
90-
console.log('BEFORE UPDATED: ', reqResObj);
9190
api.send('open-http', reqResObj, this.openConnectionArray);
9291
}
9392
},

0 commit comments

Comments
 (0)