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
This commit is contained in:
committed by
Quincy Larson
parent
f92294bbda
commit
c547c26bba
74
common/utils/map.js
Normal file
74
common/utils/map.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import emptyProtector from '../app/utils/empty-protector';
|
||||
|
||||
export function checkMapData(
|
||||
{
|
||||
entities: {
|
||||
challenge,
|
||||
block,
|
||||
superBlock
|
||||
},
|
||||
result: { superBlocks }
|
||||
}
|
||||
) {
|
||||
if (
|
||||
!challenge ||
|
||||
!block ||
|
||||
!superBlock ||
|
||||
!superBlocks ||
|
||||
!superBlocks.length
|
||||
) {
|
||||
throw new Error(
|
||||
'entities not found, db may not be properly seeded'
|
||||
);
|
||||
}
|
||||
}
|
||||
// getFirstChallenge(
|
||||
// map: {
|
||||
// entities: { challenge: Object, block: Object, superBlock: Object },
|
||||
// result: [...superBlockDashedName: String]
|
||||
// }
|
||||
// ) => Challenge|Void
|
||||
export function getFirstChallenge({
|
||||
entities: { superBlock, block, challenge },
|
||||
result: { superBlocks }
|
||||
}) {
|
||||
return challenge[
|
||||
emptyProtector(block[
|
||||
emptyProtector(superBlock[
|
||||
superBlocks[0]
|
||||
]).blocks[0]
|
||||
]).challenges[0]
|
||||
];
|
||||
}
|
||||
|
||||
// let challengeDashedName: String;
|
||||
// createNameIdMap({
|
||||
// challenge: {
|
||||
// [...challengeDashedName ]: Challenge
|
||||
// }) => {
|
||||
// challengeIdToName: {
|
||||
// [ ...challengeId ]: challengeDashedName
|
||||
// }
|
||||
// };
|
||||
export function createNameIdMap({ challenge }) {
|
||||
return {
|
||||
challengeIdToName: Object.keys(challenge)
|
||||
.reduce((map, challengeName) => {
|
||||
map[challenge[challengeName].id] =
|
||||
challenge[challengeName].dashedName;
|
||||
return map;
|
||||
}, {})
|
||||
};
|
||||
}
|
||||
// addNameIdMap(
|
||||
// map: { entities; Object, ...rest }
|
||||
// ) => { ...rest, entities: Object };
|
||||
export function addNameIdMap({ entities, ...rest }) {
|
||||
return {
|
||||
...rest,
|
||||
entities: {
|
||||
...entities,
|
||||
...createNameIdMap(entities)
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user