Files
freeCodeCamp/common/app/routes/challenges/redux/next-challenge-saga.js

25 lines
849 B
JavaScript
Raw Normal View History

2016-06-09 16:02:51 -07:00
import { Observable } from 'rx';
import { push } from 'react-router-redux';
import { moveToNextChallenge } from './types';
import { getNextChallenge } from '../utils';
import { resetUi, updateCurrentChallenge } from './actions';
2016-06-09 16:02:51 -07:00
// import { createErrorObservable, makeToast } from '../../../redux/actions';
export default function nextChallengeSaga(actions$, getState) {
return actions$
.filter(({ type }) => type === moveToNextChallenge)
.flatMap(() => {
const state = getState();
const nextChallenge = getNextChallenge(
state.challengesApp.challenge,
state.entities,
state.challengesApp.superBlocks
);
return Observable.of(
updateCurrentChallenge(nextChallenge),
resetUi(),
push(`/challenges/${nextChallenge.block}/${nextChallenge.dashedName}`)
2016-06-09 16:02:51 -07:00
);
});
}