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