logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

loading_bar.js (855B)


  1. import { showLoading, hideLoading } from 'react-redux-loading-bar';
  2. const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED'];
  3. export default function loadingBarMiddleware(config = {}) {
  4. const promiseTypeSuffixes = config.promiseTypeSuffixes || defaultTypeSuffixes;
  5. return ({ dispatch }) => next => (action) => {
  6. if (action.type && !action.skipLoading) {
  7. const [PENDING, FULFILLED, REJECTED] = promiseTypeSuffixes;
  8. const isPending = new RegExp(`${PENDING}$`, 'g');
  9. const isFulfilled = new RegExp(`${FULFILLED}$`, 'g');
  10. const isRejected = new RegExp(`${REJECTED}$`, 'g');
  11. if (action.type.match(isPending)) {
  12. dispatch(showLoading());
  13. } else if (action.type.match(isFulfilled) || action.type.match(isRejected)) {
  14. dispatch(hideLoading());
  15. }
  16. }
  17. return next(action);
  18. };
  19. };