Merge pull request #10982 from BerkeleyTrue/fix/code-storage-fresh-head-tail

Fix(code-storage): Make sure head/tail is always fresh
This commit is contained in:
Quincy Larson
2016-09-30 12:45:26 -07:00
committed by GitHub
3 changed files with 36 additions and 10 deletions

View File

@ -14,6 +14,9 @@ import {
updateMain,
lockUntrustedCode
} from '../../common/app/routes/challenges/redux/actions';
import {
challengeSelector
} from '../../common/app/routes/challenges/redux/selectors';
const legacyPrefixes = [
'Bonfire: ',
@ -72,13 +75,14 @@ export function saveCodeSaga(actions, getState) {
});
}
export function loadCodeSaga(actions$, getState, { window, location }) {
return actions$
export function loadCodeSaga(actions, getState, { window, location }) {
return actions
::ofType(types.loadCode)
.flatMap(() => {
let finalFiles;
const state = getState();
const { user } = userSelector(state);
const { challenge } = challengeSelector(state);
const {
challengesApp: {
id = '',
@ -99,7 +103,7 @@ export function loadCodeSaga(actions$, getState, { window, location }) {
makeToast({
message: 'I found code in the URI. Loading now.'
}),
savedCodeFound(finalFiles)
savedCodeFound(finalFiles, challenge)
);
}
@ -118,7 +122,7 @@ export function loadCodeSaga(actions$, getState, { window, location }) {
makeToast({
message: 'I found some saved work. Loading now.'
}),
savedCodeFound(finalFiles),
savedCodeFound(finalFiles, challenge),
updateMain()
);
}
@ -135,7 +139,7 @@ export function loadCodeSaga(actions$, getState, { window, location }) {
makeToast({
message: 'I found a previous solved solution. Loading now.'
}),
savedCodeFound(finalFiles),
savedCodeFound(finalFiles, challenge),
updateMain()
);
}

View File

@ -91,7 +91,10 @@ export const moveToNextChallenge = createAction(types.moveToNextChallenge);
// code storage
export const saveCode = createAction(types.saveCode);
export const loadCode = createAction(types.loadCode);
export const savedCodeFound = createAction(types.savedCodeFound);
export const savedCodeFound = createAction(
types.savedCodeFound,
(files, challenge) => ({ files, challenge })
);
export const clearSavedCode = createAction(types.clearSavedCode);

View File

@ -221,9 +221,29 @@ const filesReducer = handleActions(
return files;
}, { ...state });
},
[types.savedCodeFound]: (state, { payload: files }) => ({
...files
}),
[types.savedCodeFound]: (state, { payload: { files, challenge } }) => {
if (challenge.type === 'mod') {
// this may need to change to update head/tail
return challenge.files;
}
if (
challenge.challengeType !== html &&
challenge.challengeType !== js &&
challenge.challengeType !== bonfire
) {
return {};
}
// classic challenge to modern format
const preFile = getPreFile(challenge);
return {
[preFile.key]: createPoly({
...files[preFile.key],
// make sure head/tail are always fresh
head: arrayToString(challenge.head),
tail: arrayToString(challenge.tail)
})
};
},
[types.updateCurrentChallenge]: (state, { payload: challenge = {} }) => {
if (challenge.type === 'mod') {
return challenge.files;
@ -238,7 +258,6 @@ const filesReducer = handleActions(
// classic challenge to modern format
const preFile = getPreFile(challenge);
return {
...state,
[preFile.key]: createPoly({
...preFile,
contents: buildSeed(challenge),