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';
|
2016-06-10 10:45:29 -07:00
|
|
|
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),
|
2016-06-10 10:45:29 -07:00
|
|
|
resetUi(),
|
|
|
|
push(`/challenges/${nextChallenge.block}/${nextChallenge.dashedName}`)
|
2016-06-09 16:02:51 -07:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|