fix file storing for single file challenges
This commit is contained in:
@ -11,9 +11,10 @@ import { challengeSelector } from '../redux/selectors';
|
|||||||
|
|
||||||
const mapStateToProps = createSelector(
|
const mapStateToProps = createSelector(
|
||||||
challengeSelector,
|
challengeSelector,
|
||||||
state => state.challengesApp.content,
|
state => state.challengesApp.files,
|
||||||
({ challenge, showPreview, mode }, content) => ({
|
state => state.challengesApp.path,
|
||||||
content,
|
({ challenge, showPreview, mode }, files, path) => ({
|
||||||
|
content: files[path] && files[path].contents,
|
||||||
challenge,
|
challenge,
|
||||||
showPreview,
|
showPreview,
|
||||||
mode
|
mode
|
||||||
|
@ -2,6 +2,7 @@ import { handleActions } from 'redux-actions';
|
|||||||
import { createPoly } from '../../../../utils/polyvinyl';
|
import { createPoly } from '../../../../utils/polyvinyl';
|
||||||
|
|
||||||
import types from './types';
|
import types from './types';
|
||||||
|
import { HTML, JS } from '../../../utils/challengeTypes';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
challenge: '',
|
challenge: '',
|
||||||
@ -21,6 +22,15 @@ function buildSeed({ challengeSeed = [] } = {}) {
|
|||||||
return arrayToNewLineString(challengeSeed);
|
return arrayToNewLineString(challengeSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pathsMap = {
|
||||||
|
[HTML]: 'main.html',
|
||||||
|
[JS]: 'main.js'
|
||||||
|
};
|
||||||
|
|
||||||
|
function getPath({ challengeType }) {
|
||||||
|
return pathsMap[challengeType] || 'main';
|
||||||
|
}
|
||||||
|
|
||||||
const mainReducer = handleActions(
|
const mainReducer = handleActions(
|
||||||
{
|
{
|
||||||
[types.fetchChallengeCompleted]: (state, { payload = '' }) => ({
|
[types.fetchChallengeCompleted]: (state, { payload = '' }) => ({
|
||||||
@ -29,7 +39,8 @@ const mainReducer = handleActions(
|
|||||||
}),
|
}),
|
||||||
[types.updateCurrentChallenge]: (state, { payload: challenge }) => ({
|
[types.updateCurrentChallenge]: (state, { payload: challenge }) => ({
|
||||||
...state,
|
...state,
|
||||||
challenge: challenge.dashedName
|
challenge: challenge.dashedName,
|
||||||
|
path: getPath(challenge)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// map
|
// map
|
||||||
@ -71,10 +82,22 @@ const filesReducer = handleActions(
|
|||||||
}, { ...state });
|
}, { ...state });
|
||||||
},
|
},
|
||||||
[types.updateCurrentChallenge]: (state, { payload: challenge }) => {
|
[types.updateCurrentChallenge]: (state, { payload: challenge }) => {
|
||||||
const path = challenge.dashedName + challenge.type;
|
if (challenge.type === 'mod') {
|
||||||
|
return challenge.files;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
challenge.challengeType !== HTML &&
|
||||||
|
challenge.challengeType !== JS
|
||||||
|
) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const path = getPath(challenge);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
[path]: createPoly({ path, contents: buildSeed(challenge) })
|
[path]: createPoly({
|
||||||
|
path,
|
||||||
|
contents: buildSeed(challenge)
|
||||||
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user