Add map aside to challenges
This commit is contained in:
@ -189,6 +189,15 @@ function getRenderData$(user, challenge$, origChallengeName, solution) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCompletedChallengeIds(user = {}) {
|
||||||
|
// if user
|
||||||
|
// get the id's of all the users completed challenges
|
||||||
|
return !user.completedChallenges ?
|
||||||
|
[] :
|
||||||
|
_.uniq(user.completedChallenges)
|
||||||
|
.map(({ id, _id }) => id || _id);
|
||||||
|
}
|
||||||
|
|
||||||
// create a stream of an array of all the challenge blocks
|
// create a stream of an array of all the challenge blocks
|
||||||
function getSuperBlocks$(challenge$, completedChallenges) {
|
function getSuperBlocks$(challenge$, completedChallenges) {
|
||||||
return challenge$
|
return challenge$
|
||||||
@ -406,7 +415,19 @@ module.exports = function(app) {
|
|||||||
|
|
||||||
function showChallenge(req, res, next) {
|
function showChallenge(req, res, next) {
|
||||||
const solution = req.query.solution;
|
const solution = req.query.solution;
|
||||||
getRenderData$(req.user, challenge$, req.params.challengeName, solution)
|
const completedChallenges = getCompletedChallengeIds(req.user);
|
||||||
|
|
||||||
|
Observable.combineLatest(
|
||||||
|
getRenderData$(req.user, challenge$, req.params.challengeName, solution),
|
||||||
|
getSuperBlocks$(challenge$, completedChallenges),
|
||||||
|
({ data, ...rest }, superBlocks) => ({
|
||||||
|
...rest,
|
||||||
|
data: {
|
||||||
|
...data,
|
||||||
|
superBlocks
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
({ type, redirectUrl, message, data }) => {
|
({ type, redirectUrl, message, data }) => {
|
||||||
if (message) {
|
if (message) {
|
||||||
@ -552,14 +573,9 @@ module.exports = function(app) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showMap({ user = {} }, res, next) {
|
function showMap({ user }, res, next) {
|
||||||
// if user
|
|
||||||
// get the id's of all the users completed challenges
|
|
||||||
const completedChallenges = !user.completedChallenges ?
|
|
||||||
[] :
|
|
||||||
_.uniq(user.completedChallenges).map(({ id, _id }) => id || _id);
|
|
||||||
|
|
||||||
getSuperBlocks$(challenge$, completedChallenges)
|
getSuperBlocks$(challenge$, getCompletedChallengeIds(user))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
superBlocks => {
|
superBlocks => {
|
||||||
res.render('map/show', {
|
res.render('map/show', {
|
||||||
|
Reference in New Issue
Block a user