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

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-05-10 13:17:57 -07:00
import { createSelector } from 'reselect';
2016-10-29 00:46:45 +01:00
import { viewTypes, submitTypes, getNode } from '../utils';
2016-10-29 00:46:45 +01:00
import blockNameify from '../../../utils/blockNameify';
import { html } from '../../../utils/challengeTypes';
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;
const type = challenge && challenge.type;
const viewType = viewTypes[type] || viewTypes[challengeType] || 'classic';
2016-10-29 00:46:45 +01:00
const blockName = blockNameify(challenge.block);
const title = blockName && challenge.title ?
`${blockName}: ${challenge.title}` :
challenge.title;
2016-05-10 13:17:57 -07:00
return {
2016-06-07 20:41:42 -07:00
challenge,
2016-10-29 00:46:45 +01:00
title,
viewType,
submitType:
submitTypes[challengeType] ||
submitTypes[challenge && challenge.type] ||
'tests',
showPreview: challengeType === html,
mode: challenge && challengeType === html ?
2016-05-10 13:17:57 -07:00
'text/html' :
'javascript'
};
}
);
export const makePanelOpenSelector = () => createSelector(
state => state.challengesApp.mapUi,
(_, props) => props.dashedName,
(mapUi, name) => {
const node = getNode(mapUi, name);
return node ? node.isOpen : true;
}
);
export const makePanelHiddenSelector = () => createSelector(
state => state.challengesApp.mapUi,
(_, props) => props.dashedName,
(mapUi, name) => {
const node = getNode(mapUi, name);
return node ? node.isHidden : false;
}
);