mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-27 23:01:36 +01:00
155424e52f
I don't like it changing files this way, but it's basically what
c49213f0ea
and a few others did.
25 lines
854 B
JavaScript
25 lines
854 B
JavaScript
import { showLoading, hideLoading } from 'react-redux-loading-bar';
|
|
|
|
const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED'];
|
|
|
|
export default function loadingBarMiddleware(config = {}) {
|
|
const promiseTypeSuffixes = config.promiseTypeSuffixes || defaultTypeSuffixes;
|
|
|
|
return ({ dispatch }) => next => (action) => {
|
|
if (action.type && !action.skipLoading) {
|
|
const [PENDING, FULFILLED, REJECTED] = promiseTypeSuffixes;
|
|
|
|
const isPending = new RegExp(`${PENDING}$`, 'g');
|
|
const isFulfilled = new RegExp(`${FULFILLED}$`, 'g');
|
|
const isRejected = new RegExp(`${REJECTED}$`, 'g');
|
|
|
|
if (action.type.match(isPending)) {
|
|
dispatch(showLoading());
|
|
} else if (action.type.match(isFulfilled) || action.type.match(isRejected)) {
|
|
dispatch(hideLoading());
|
|
}
|
|
}
|
|
|
|
return next(action);
|
|
};
|
|
}
|