import { ofType } from 'redux-observable';
import { concat, of } from 'rxjs';
import { delay, switchMap } from 'rxjs/operators';

import { loadingAction } from '../slices';
import { locationChangedEventAction, locationLoadedEventAction } from '@/modules/@common/location/redux/slices';

export default (action$) =>
  action$.pipe(
    ofType(locationChangedEventAction.type, locationLoadedEventAction.type),
    delay(+process.env.APP_REQUEST_TIMEOUT),
    switchMap(() => concat(of(loadingAction()))),
  );
