Move from one challenge to another within a block

This commit is contained in:
Berkeley Martinez
2016-06-10 10:45:29 -07:00
parent 5d4a92bcc6
commit c0015a4050
7 changed files with 30 additions and 16 deletions

View File

@ -18,6 +18,7 @@ export const fetchChallengeCompleted = createAction(
(_, challenge) => challenge, (_, challenge) => challenge,
entities => ({ entities }) entities => ({ entities })
); );
export const resetUi = createAction(types.resetUi);
export const fetchChallenges = createAction(types.fetchChallenges); export const fetchChallenges = createAction(types.fetchChallenges);
export const fetchChallengesCompleted = createAction( export const fetchChallengesCompleted = createAction(

View File

@ -154,8 +154,8 @@ function submitSimpleChallenge(type, state) {
title: randomCompliment(), title: randomCompliment(),
message: isSignedIn ? ' Saving...' : 'Moving on to next challenge.', message: isSignedIn ? ' Saving...' : 'Moving on to next challenge.',
type: 'success' type: 'success'
}) }),
// moveToNextChallenge() moveToNextChallenge()
); );
return Observable.merge(saveChallenge$, challengeCompleted$); return Observable.merge(saveChallenge$, challengeCompleted$);
} }

View File

@ -4,7 +4,12 @@ export types from './types';
import fetchChallengesSaga from './fetch-challenges-saga'; import fetchChallengesSaga from './fetch-challenges-saga';
import completionSaga from './completion-saga'; import completionSaga from './completion-saga';
import nextChallengeSaga from './next-challenge-saga';
export projectNormalizer from './project-normalizer'; export projectNormalizer from './project-normalizer';
export const sagas = [ fetchChallengesSaga, completionSaga ]; export const sagas = [
fetchChallengesSaga,
completionSaga,
nextChallengeSaga
];

View File

@ -2,7 +2,7 @@ import { Observable } from 'rx';
import { push } from 'react-router-redux'; import { push } from 'react-router-redux';
import { moveToNextChallenge } from './types'; import { moveToNextChallenge } from './types';
import { getNextChallenge } from '../utils'; import { getNextChallenge } from '../utils';
import { updateCurrentChallenge } from './actions'; import { resetUi, updateCurrentChallenge } from './actions';
// import { createErrorObservable, makeToast } from '../../../redux/actions'; // import { createErrorObservable, makeToast } from '../../../redux/actions';
export default function nextChallengeSaga(actions$, getState) { export default function nextChallengeSaga(actions$, getState) {
@ -17,7 +17,8 @@ export default function nextChallengeSaga(actions$, getState) {
); );
return Observable.of( return Observable.of(
updateCurrentChallenge(nextChallenge), updateCurrentChallenge(nextChallenge),
push(`/challenges/${nextChallenge.dashedName}`) resetUi(),
push(`/challenges/${nextChallenge.block}/${nextChallenge.dashedName}`)
); );
}); });
} }

View File

@ -11,21 +11,24 @@ import {
getFileKey getFileKey
} from '../utils'; } from '../utils';
const initialState = { const initialUiState = {
id: '',
challenge: '',
legacyKey: '',
// step
currentIndex: 0, currentIndex: 0,
previousIndex: -1, previousIndex: -1,
isActionCompleted: false, isActionCompleted: false,
isSubmitting: true
};
const initialState = {
id: '',
challenge: '',
// old code storage key
legacyKey: '',
files: {},
// map // map
filter: '', filter: '',
superBlocks: [], superBlocks: [],
// modern
files: {},
// misc // misc
toast: 0 toast: 0,
...initialUiState
}; };
const mainReducer = handleActions( const mainReducer = handleActions(
@ -59,6 +62,10 @@ const mainReducer = handleActions(
...state, ...state,
isSubmitting: true isSubmitting: true
}), }),
[types.resetUi]: (state) => ({
...state,
...initialUiState
}),
// map // map
[types.updateFilter]: (state, { payload = ''}) => ({ [types.updateFilter]: (state, { payload = ''}) => ({
@ -75,7 +82,6 @@ const mainReducer = handleActions(
}), }),
// step // step
[types.resetStep]: () => initialState,
[types.goToStep]: (state, { payload: step = 0 }) => ({ [types.goToStep]: (state, { payload: step = 0 }) => ({
...state, ...state,
currentIndex: step, currentIndex: step,
@ -128,6 +134,7 @@ const filesReducer = handleActions(
) { ) {
return {}; return {};
} }
// classic challenge to modern format
const preFile = getPreFile(challenge); const preFile = getPreFile(challenge);
return { return {
...state, ...state,

View File

@ -11,6 +11,7 @@ export default createTypes([
'fetchChallengeCompleted', 'fetchChallengeCompleted',
'fetchChallengesCompleted', 'fetchChallengesCompleted',
'updateCurrentChallenge', 'updateCurrentChallenge',
'resetUi',
// map // map
'updateFilter', 'updateFilter',

View File

@ -1,6 +1,5 @@
import { compose } from 'redux'; import { compose } from 'redux';
import { bonfire, html, js } from '../../utils/challengeTypes'; import { bonfire, html, js } from '../../utils/challengeTypes';
import { dashify } from '../../../utils';
export function encodeScriptTags(value) { export function encodeScriptTags(value) {
return value return value
@ -103,7 +102,7 @@ export function getNextChallenge(
// find next challenge in block // find next challenge in block
const currentChallenge = challengeMap[current]; const currentChallenge = challengeMap[current];
if (currentChallenge) { if (currentChallenge) {
const block = blockMap[dashify(currentChallenge.block)]; const block = blockMap[currentChallenge.block];
const index = block.challenges.indexOf(currentChallenge.dashedName); const index = block.challenges.indexOf(currentChallenge.dashedName);
return challengeMap[block.challenges[index + 1]]; return challengeMap[block.challenges[index + 1]];
} }