Move from one challenge to another within a block
This commit is contained in:
@ -18,6 +18,7 @@ export const fetchChallengeCompleted = createAction(
|
||||
(_, challenge) => challenge,
|
||||
entities => ({ entities })
|
||||
);
|
||||
export const resetUi = createAction(types.resetUi);
|
||||
|
||||
export const fetchChallenges = createAction(types.fetchChallenges);
|
||||
export const fetchChallengesCompleted = createAction(
|
||||
|
@ -154,8 +154,8 @@ function submitSimpleChallenge(type, state) {
|
||||
title: randomCompliment(),
|
||||
message: isSignedIn ? ' Saving...' : 'Moving on to next challenge.',
|
||||
type: 'success'
|
||||
})
|
||||
// moveToNextChallenge()
|
||||
}),
|
||||
moveToNextChallenge()
|
||||
);
|
||||
return Observable.merge(saveChallenge$, challengeCompleted$);
|
||||
}
|
||||
|
@ -4,7 +4,12 @@ export types from './types';
|
||||
|
||||
import fetchChallengesSaga from './fetch-challenges-saga';
|
||||
import completionSaga from './completion-saga';
|
||||
import nextChallengeSaga from './next-challenge-saga';
|
||||
|
||||
export projectNormalizer from './project-normalizer';
|
||||
|
||||
export const sagas = [ fetchChallengesSaga, completionSaga ];
|
||||
export const sagas = [
|
||||
fetchChallengesSaga,
|
||||
completionSaga,
|
||||
nextChallengeSaga
|
||||
];
|
||||
|
@ -2,7 +2,7 @@ import { Observable } from 'rx';
|
||||
import { push } from 'react-router-redux';
|
||||
import { moveToNextChallenge } from './types';
|
||||
import { getNextChallenge } from '../utils';
|
||||
import { updateCurrentChallenge } from './actions';
|
||||
import { resetUi, updateCurrentChallenge } from './actions';
|
||||
// import { createErrorObservable, makeToast } from '../../../redux/actions';
|
||||
|
||||
export default function nextChallengeSaga(actions$, getState) {
|
||||
@ -17,7 +17,8 @@ export default function nextChallengeSaga(actions$, getState) {
|
||||
);
|
||||
return Observable.of(
|
||||
updateCurrentChallenge(nextChallenge),
|
||||
push(`/challenges/${nextChallenge.dashedName}`)
|
||||
resetUi(),
|
||||
push(`/challenges/${nextChallenge.block}/${nextChallenge.dashedName}`)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -11,21 +11,24 @@ import {
|
||||
getFileKey
|
||||
} from '../utils';
|
||||
|
||||
const initialState = {
|
||||
id: '',
|
||||
challenge: '',
|
||||
legacyKey: '',
|
||||
// step
|
||||
const initialUiState = {
|
||||
currentIndex: 0,
|
||||
previousIndex: -1,
|
||||
isActionCompleted: false,
|
||||
isSubmitting: true
|
||||
};
|
||||
const initialState = {
|
||||
id: '',
|
||||
challenge: '',
|
||||
// old code storage key
|
||||
legacyKey: '',
|
||||
files: {},
|
||||
// map
|
||||
filter: '',
|
||||
superBlocks: [],
|
||||
// modern
|
||||
files: {},
|
||||
// misc
|
||||
toast: 0
|
||||
toast: 0,
|
||||
...initialUiState
|
||||
};
|
||||
|
||||
const mainReducer = handleActions(
|
||||
@ -59,6 +62,10 @@ const mainReducer = handleActions(
|
||||
...state,
|
||||
isSubmitting: true
|
||||
}),
|
||||
[types.resetUi]: (state) => ({
|
||||
...state,
|
||||
...initialUiState
|
||||
}),
|
||||
|
||||
// map
|
||||
[types.updateFilter]: (state, { payload = ''}) => ({
|
||||
@ -75,7 +82,6 @@ const mainReducer = handleActions(
|
||||
}),
|
||||
|
||||
// step
|
||||
[types.resetStep]: () => initialState,
|
||||
[types.goToStep]: (state, { payload: step = 0 }) => ({
|
||||
...state,
|
||||
currentIndex: step,
|
||||
@ -128,6 +134,7 @@ const filesReducer = handleActions(
|
||||
) {
|
||||
return {};
|
||||
}
|
||||
// classic challenge to modern format
|
||||
const preFile = getPreFile(challenge);
|
||||
return {
|
||||
...state,
|
||||
|
@ -11,6 +11,7 @@ export default createTypes([
|
||||
'fetchChallengeCompleted',
|
||||
'fetchChallengesCompleted',
|
||||
'updateCurrentChallenge',
|
||||
'resetUi',
|
||||
|
||||
// map
|
||||
'updateFilter',
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { compose } from 'redux';
|
||||
import { bonfire, html, js } from '../../utils/challengeTypes';
|
||||
import { dashify } from '../../../utils';
|
||||
|
||||
export function encodeScriptTags(value) {
|
||||
return value
|
||||
@ -103,7 +102,7 @@ export function getNextChallenge(
|
||||
// find next challenge in block
|
||||
const currentChallenge = challengeMap[current];
|
||||
if (currentChallenge) {
|
||||
const block = blockMap[dashify(currentChallenge.block)];
|
||||
const block = blockMap[currentChallenge.block];
|
||||
const index = block.challenges.indexOf(currentChallenge.dashedName);
|
||||
return challengeMap[block.challenges[index + 1]];
|
||||
}
|
||||
|
Reference in New Issue
Block a user