Skip to content

Commit 4b7f4f7

Browse files
author
esa
committed
Cleanup and comment
1 parent b822e2c commit 4b7f4f7

File tree

1 file changed

+51
-64
lines changed

1 file changed

+51
-64
lines changed

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

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,35 @@ export default function TRPCComposer(props) {
138138
}
139139
}
140140

141+
const dispatchTRPCResponse = (tRPCResponse) => {
142+
143+
const newCurrentResponse: any = {
144+
checkSelected: false,
145+
checked: false,
146+
connection: 'closed',
147+
connectionType: 'plain',
148+
createdAt: new Date(),
149+
gRPC: false,
150+
graphQL: false,
151+
host: requestFields.url,
152+
id: uuid(),
153+
minimized: false,
154+
path: '/',
155+
protoPath: undefined,
156+
protocol: 'http://',
157+
request: { ...newRequest },
158+
tab: undefined,
159+
timeReceived: null,
160+
timeSent: null,
161+
url: requestFields.url,
162+
webrtc: false,
163+
response: {
164+
events: [tRPCResponse],
165+
},
166+
};
167+
dispatch(responseDataSaved(newCurrentResponse));
168+
}
169+
141170
const sendRequest = async () => {
142171
const links = [];
143172
const batchConfigureObject = {};
@@ -154,81 +183,39 @@ export default function TRPCComposer(props) {
154183
links.push(httpBatchLink(batchConfigureObject));
155184

156185
const client = createTRPCProxyClient({ links });
157-
158-
const dispatchTRPCResponse = (tRPCResponse) => {
159-
160-
const newCurrentResponse: any = {
161-
checkSelected: false,
162-
checked: false,
163-
connection: 'closed',
164-
connectionType: 'plain',
165-
createdAt: new Date(),
166-
gRPC: false,
167-
graphQL: false,
168-
host: requestFields.url,
169-
id: uuid(),
170-
minimized: false,
171-
path: '/',
172-
protoPath: undefined,
173-
protocol: 'http://',
174-
request: { ...newRequest },
175-
tab: undefined,
176-
timeReceived: null,
177-
timeSent: null,
178-
url: requestFields.url,
179-
webrtc: false,
180-
response: {
181-
events: [tRPCResponse],
182-
},
183-
};
184-
dispatch(responseDataSaved(newCurrentResponse));
185-
}
186-
186+
187+
// processes the request variables, sends the request to the tRPC endpoint, and handles any errors
187188
Promise.all(
188189

189190
procedures.map((procedure) => {
190191
let endpoint = procedure.endpoint;
191192
const method = procedure.method.toLowerCase();
192-
193+
let tempArg = '';
194+
193195
if (procedure.variable) {
194196
let arg = parseString(procedure.variable.replace(/\s/g, ''));
195-
const tempArg = procedure.variable.replace(/\s/g, '');
196-
const e = `client.${endpoint}.${method}(${tempArg})`;
197-
198-
new Promise((resolve, reject) => {
199-
try {
200-
const result = eval(e);
201-
resolve(result);
202-
} catch (error) {
203-
reject(error);
204-
}
205-
}).then(res => {
206-
dispatchTRPCResponse(res);
207-
}).catch(error => {
208-
dispatchTRPCResponse(error);
209-
})
210-
197+
tempArg = procedure.variable.replace(/\s/g, '');
198+
}
199+
const e = `client.${endpoint}.${method}(${tempArg})`;
211200

212-
} else {
213-
214-
new Promise((resolve, reject) => {
215-
try {
216-
const result = eval(`client.${endpoint}.${method}()`);
217-
resolve(result);
218-
} catch (error) {
219-
reject(error);
220-
}
221-
}).then(res => {
201+
new Promise((resolve, reject) => {
202+
try {
203+
const result = eval(e);
204+
resolve(result);
205+
} catch (error) {
206+
reject(error);
207+
}
208+
})
209+
.then(res => {
222210
dispatchTRPCResponse(res);
223-
}).catch(error => {
224-
dispatchTRPCResponse(error);
211+
})
212+
.catch(error => {
213+
dispatchTRPCResponse(error);
225214
})
226-
227-
228-
}
229215
})
230-
231-
)}
216+
)
217+
}
218+
232219
return (
233220
<Box
234221
className="is-flex is-flex-direction-column is-justify-content-space-between"

0 commit comments

Comments
 (0)