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

import { monitoringAction, monitoringInProgressAction, monitoringStartAction } from '../slices';

export default (action$) =>
  action$.pipe(
    ofType(monitoringStartAction.type),
    filter((action) => action.payload !== null),
    switchMap(() => concat(of(monitoringInProgressAction(true)), of(monitoringAction(false)))),
  );
