mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import {combineReducers} from 'redux';
|
|
|
|
import * as network from '../../../backend/network';
|
|
import {trackEvent, trackLegacyEvent} from '../../../backend/analytics';
|
|
|
|
export const REQUEST_SEND_START = 'requests/start';
|
|
export const REQUEST_SEND_STOP = 'requests/stop';
|
|
|
|
|
|
// ~~~~~~~~ //
|
|
// REDUCERS //
|
|
// ~~~~~~~~ //
|
|
|
|
function loadingRequestsReducer(state = {}, action) {
|
|
let newState;
|
|
switch (action.type) {
|
|
|
|
case REQUEST_SEND_START:
|
|
newState = Object.assign({}, state);
|
|
newState[action.requestId] = Date.now();
|
|
return newState;
|
|
|
|
case REQUEST_SEND_STOP:
|
|
newState = Object.assign({}, state);
|
|
delete newState[action.requestId];
|
|
return newState;
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default combineReducers({
|
|
loadingRequests: loadingRequestsReducer,
|
|
doNotPersist: () => true,
|
|
});
|
|
|
|
|
|
// ~~~~~~~ //
|
|
// ACTIONS //
|
|
// ~~~~~~~ //
|
|
|
|
export function send(request, environmentId) {
|
|
return async function (dispatch) {
|
|
dispatch({type: REQUEST_SEND_START, requestId: request._id});
|
|
|
|
trackEvent('Request', 'Send');
|
|
trackLegacyEvent('Request Send');
|
|
|
|
try {
|
|
await network.send(request._id, environmentId);
|
|
dispatch({type: REQUEST_SEND_STOP, requestId: request._id});
|
|
} catch (e) {
|
|
// console.info('Error sending request', e);
|
|
dispatch({type: REQUEST_SEND_STOP, requestId: request._id});
|
|
}
|
|
}
|
|
}
|