freeCodeCamp/common/app/redux/utils.js

36 lines
862 B
JavaScript

import flowRight from 'lodash/flowRight';
import { createNameIdMap } from '../../utils/map.js';
export function filterComingSoonBetaChallenge(
isDev = false,
{ isComingSoon, isBeta }
) {
return !(isComingSoon || isBeta) ||
isDev;
}
export function filterComingSoonBetaFromEntities(
{ challenge: challengeMap, ...rest },
isDev = false
) {
const filter = filterComingSoonBetaChallenge.bind(null, isDev);
return {
...rest,
challenge: Object.keys(challengeMap)
.map(dashedName => challengeMap[dashedName])
.filter(filter)
.reduce((challengeMap, challenge) => {
challengeMap[challenge.dashedName] = challenge;
return challengeMap;
}, {})
};
}
export const shapeChallenges = flowRight(
filterComingSoonBetaFromEntities,
entities => ({
...entities,
...createNameIdMap(entities)
})
);