Files
freeCodeCamp/common/app/routes/challenges/redux/selectors.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-06-03 14:12:56 -07:00
import * as challengeTypes from '../../../utils/challengeTypes';
2016-05-10 13:17:57 -07:00
import { createSelector } from 'reselect';
2016-06-03 14:12:56 -07:00
const viewTypes = {
2016-06-07 20:41:42 -07:00
[ challengeTypes.html]: 'classic',
[ challengeTypes.js ]: 'classic',
[ challengeTypes.bonfire ]: 'classic',
[ challengeTypes.frontEndProject]: 'project',
[ challengeTypes.backEndProject]: 'project',
2016-06-03 14:12:56 -07:00
// might not be used anymore
2016-06-07 20:41:42 -07:00
[ challengeTypes.simpleProject]: 'project',
2016-06-03 14:12:56 -07:00
// formally hikes
2016-06-07 20:41:42 -07:00
[ challengeTypes.video ]: 'video',
[ challengeTypes.step ]: 'step'
};
const submitTypes = {
[ challengeTypes.html ]: 'tests',
[ challengeTypes.js ]: 'tests',
[ challengeTypes.bonfire ]: 'tests',
// requires just a button press
[ challengeTypes.simpleProject ]: 'project.simple',
// requires just a single url
// like codepen.com/my-project
[ challengeTypes.frontEndProject ]: 'project.frontEnd',
// requires two urls
// a hosted URL where the app is running live
// project code url like GitHub
[ challengeTypes.backEndProject ]: 'project.backEnd',
// formally hikes
[ challengeTypes.video ]: 'video',
[ challengeTypes.step ]: 'step'
2016-06-03 14:12:56 -07:00
};
2016-05-10 13:17:57 -07:00
export const challengeSelector = createSelector(
state => state.challengesApp.challenge,
state => state.entities.challenge,
(challengeName, challengeMap) => {
if (!challengeName || !challengeMap) {
return {};
}
const challenge = challengeMap[challengeName];
2016-06-07 20:41:42 -07:00
const challengeType = challenge && challenge.challengeType;
2016-05-10 13:17:57 -07:00
return {
2016-06-07 20:41:42 -07:00
challenge,
viewType: viewTypes[challengeType] || 'classic',
submitType: submitTypes[challengeType] || 'tests',
showPreview: challengeType === challengeTypes.html,
mode: challenge && challengeType === challengeTypes.html ?
2016-05-10 13:17:57 -07:00
'text/html' :
'javascript'
};
}
);