feat: improved request queuing status functionality

This commit is contained in:
Anoop M D 2023-01-29 13:20:19 +05:30
parent b2c28465e9
commit 050ee2680f
4 changed files with 29 additions and 2 deletions

View File

@ -17,7 +17,7 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
const dispatch = useDispatch();
const tabs = useSelector((state) => state.tabs.tabs);
const activeTabUid = useSelector((state) => state.tabs.activeTabUid);
const isLoading = item.response && item.response.state === 'sending';
const isLoading = ['queued', 'sending'].includes(item.requestState);
const selectTab = (tab) => {
dispatch(

View File

@ -8,6 +8,7 @@ import {
collectionUnlinkDirectoryEvent,
collectionUnlinkEnvFileEvent,
requestSentEvent,
requestQueuedEvent,
scriptEnvironmentUpdateEvent
} from 'providers/ReduxStore/slices/collections';
import toast from 'react-hot-toast';
@ -90,6 +91,10 @@ const useCollectionTreeSync = () => {
dispatch(scriptEnvironmentUpdateEvent(val));
};
const _httpRequestQueued = (val) => {
dispatch(requestQueuedEvent(val));
};
ipcRenderer.invoke('renderer:ready');
const removeListener1 = ipcRenderer.on('main:collection-opened', _openCollection);
@ -98,6 +103,7 @@ const useCollectionTreeSync = () => {
const removeListener4 = ipcRenderer.on('main:display-error', _displayError);
const removeListener5 = ipcRenderer.on('main:http-request-sent', _httpRequestSent);
const removeListener6 = ipcRenderer.on('main:script-environment-update', _scriptEnvironmentUpdate);
const removeListener7 = ipcRenderer.on('main:http-request-queued', _httpRequestQueued);
return () => {
removeListener1();
@ -106,6 +112,7 @@ const useCollectionTreeSync = () => {
removeListener4();
removeListener5();
removeListener6();
removeListener7();
};
}, [isElectron]);
};

View File

@ -157,7 +157,19 @@ export const collectionsSlice = createSlice({
if (item) {
item.requestSent = requestSent
item.response = item.response || {};
item.response.state = 'sending';
item.requestState = 'sending';
item.cancelTokenUid = cancelTokenUid;
}
}
},
requestQueuedEvent: (state, action) => {
const { itemUid, collectionUid, cancelTokenUid } = action.payload;
const collection = findCollectionByUid(state.collections, collectionUid);
if (collection) {
const item = findItemInCollection(collection, itemUid);
if (item) {
item.requestState = 'queued';
item.cancelTokenUid = cancelTokenUid;
}
}
@ -199,6 +211,7 @@ export const collectionsSlice = createSlice({
if (collection) {
const item = findItemInCollection(collection, action.payload.itemUid);
if (item) {
item.requestState = 'received';
item.response = action.payload.response;
item.cancelTokenUid = null;
}
@ -816,6 +829,7 @@ export const {
renameItem,
cloneItem,
requestSentEvent,
requestQueuedEvent,
scriptEnvironmentUpdateEvent,
requestCancelled,
responseReceived,

View File

@ -52,6 +52,12 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
const cancelTokenUid = uuid();
try {
mainWindow.webContents.send('main:http-request-queued', {
collectionUid,
itemUid: item.uid,
cancelTokenUid
});
const _request = item.draft ? item.draft.request : item.request;
const request = prepareRequest(_request);