Files
freeCodeCamp/common/app/redux/utils.js
Berkeley Martinez c547c26bba Fix: map should redirect to current challenge (#15723)
* fix(routes): /map redirects to current challenge

* fix(map): Normalize server map building

Localize all server code dealing with the map

* refactor(server): Remove unused services

* feat(Nav): Show Map button when no panes

This gives user the ability to quickly return to their challenge using a
known feature

* fix(server.map): Add caching to nameIdMap

Add caching to nameIdMap on the server

* fix(services.map): Fix map service

Move map building utils to map util. Fix bad import. Normalize challenge
lookup
2017-08-03 22:45:36 -05:00

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)
})
);