make one page profile with bonfire solution urls
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
||||
|
||||
import {
|
||||
userMigration,
|
||||
ifNoUserRedirectTo,
|
||||
ifNoUserSend
|
||||
} from '../utils/middleware';
|
||||
|
||||
@@ -27,7 +26,8 @@ const challengeView = {
|
||||
2: 'coursewares/showVideo',
|
||||
3: 'coursewares/showZiplineOrBasejump',
|
||||
4: 'coursewares/showZiplineOrBasejump',
|
||||
5: 'coursewares/showBonfire'
|
||||
5: 'coursewares/showBonfire',
|
||||
7: 'coursewares/showStep'
|
||||
};
|
||||
|
||||
const dasherize = utils.dasherize;
|
||||
@@ -100,9 +100,6 @@ module.exports = function(app) {
|
||||
const userCount$ = observeMethod(User, 'count');
|
||||
|
||||
const send200toNonUser = ifNoUserSend(true);
|
||||
const redirectNonUser = ifNoUserRedirectTo(
|
||||
'/challenges/learn-how-free-code-camp-works'
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/completed-challenge/',
|
||||
@@ -125,26 +122,17 @@ module.exports = function(app) {
|
||||
router.get('/map', challengeMap);
|
||||
router.get(
|
||||
'/challenges/next-challenge',
|
||||
redirectNonUser,
|
||||
returnNextChallenge
|
||||
);
|
||||
|
||||
router.get('/challenges/:challengeName', returnIndividualChallenge);
|
||||
|
||||
router.get(
|
||||
'/challenges/',
|
||||
redirectNonUser,
|
||||
returnCurrentChallenge
|
||||
);
|
||||
|
||||
app.use(router);
|
||||
|
||||
function returnNextChallenge(req, res, next) {
|
||||
let nextChallengeName = firstChallenge;
|
||||
|
||||
const challengeId = req.user.currentChallenge ?
|
||||
req.user.currentChallenge.challengeId :
|
||||
'bd7123c8c441eddfaeb5bdef';
|
||||
const challengeId = req.query.id;
|
||||
|
||||
// find challenge
|
||||
return challenge$
|
||||
@@ -199,16 +187,13 @@ module.exports = function(app) {
|
||||
nextChallengeName = nextChallenge.dashedName;
|
||||
return nextChallengeName;
|
||||
})
|
||||
.flatMap(() => {
|
||||
return saveUser(req.user);
|
||||
})
|
||||
.subscribe(
|
||||
function() {},
|
||||
next,
|
||||
function() {
|
||||
debug('next challengeName', nextChallengeName);
|
||||
if (!nextChallengeName || nextChallengeName === firstChallenge) {
|
||||
req.flash('errors', {
|
||||
req.flash('info', {
|
||||
msg: dedent`
|
||||
Once you have completed all of our challenges, you should
|
||||
join our <a href=\"//gitter.im/freecodecamp/HalfWayClub\"
|
||||
@@ -223,36 +208,9 @@ module.exports = function(app) {
|
||||
);
|
||||
}
|
||||
|
||||
function returnCurrentChallenge(req, res, next) {
|
||||
Observable.just(req.user)
|
||||
.flatMap(user => {
|
||||
if (!req.user.currentChallenge) {
|
||||
return challenge$
|
||||
.first()
|
||||
.flatMap(challenge => {
|
||||
user.currentChallenge = {
|
||||
challengeId: challenge.id,
|
||||
challengeName: challenge.name,
|
||||
dashedName: challenge.dashedName
|
||||
};
|
||||
return saveUser(user);
|
||||
});
|
||||
}
|
||||
return Observable.just(user);
|
||||
})
|
||||
.map(user => user.currentChallenge.dashedName)
|
||||
.subscribe(
|
||||
function(challengeName) {
|
||||
res.redirect('/challenges/' + challengeName);
|
||||
},
|
||||
next,
|
||||
function() {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function returnIndividualChallenge(req, res, next) {
|
||||
const origChallengeName = req.params.challengeName;
|
||||
const solutionCode = req.query.solution;
|
||||
const unDashedName = unDasherize(origChallengeName);
|
||||
|
||||
const challengeName = challengesRegex.test(unDashedName) ?
|
||||
@@ -282,43 +240,33 @@ module.exports = function(app) {
|
||||
}
|
||||
|
||||
if (dasherize(challenge.name) !== origChallengeName) {
|
||||
return Observable.just('/challenges/' + dasherize(challenge.name));
|
||||
return Observable.just('/challenges/' + dasherize(challenge.name) + '?solution=' + solutionCode);
|
||||
}
|
||||
|
||||
if (challenge) {
|
||||
if (req.user) {
|
||||
req.user.currentChallenge = {
|
||||
challengeId: challenge.id,
|
||||
challengeName: challenge.name,
|
||||
dashedName: challenge.dashedName
|
||||
};
|
||||
}
|
||||
|
||||
// save user does nothing if user does not exist
|
||||
return saveUser(req.user)
|
||||
.map(() => ({
|
||||
title: challenge.name,
|
||||
dashedName: origChallengeName,
|
||||
name: challenge.name,
|
||||
details: challenge.description,
|
||||
tests: challenge.tests,
|
||||
challengeSeed: challenge.challengeSeed,
|
||||
verb: utils.randomVerb(),
|
||||
phrase: utils.randomPhrase(),
|
||||
compliment: utils.randomCompliment(),
|
||||
challengeId: challenge.id,
|
||||
challengeType: challenge.challengeType,
|
||||
// video challenges
|
||||
video: challenge.challengeSeed[0],
|
||||
// bonfires specific
|
||||
difficulty: Math.floor(+challenge.difficulty),
|
||||
bonfires: challenge,
|
||||
MDNkeys: challenge.MDNlinks,
|
||||
MDNlinks: getMDNLinks(challenge.MDNlinks),
|
||||
// htmls specific
|
||||
environment: utils.whichEnvironment()
|
||||
}));
|
||||
}
|
||||
// save user does nothing if user does not exist
|
||||
return Observable.just({
|
||||
title: challenge.name,
|
||||
dashedName: origChallengeName,
|
||||
name: challenge.name,
|
||||
details: challenge.description,
|
||||
description: challenge.description,
|
||||
tests: challenge.tests,
|
||||
challengeSeed: challenge.challengeSeed,
|
||||
verb: utils.randomVerb(),
|
||||
phrase: utils.randomPhrase(),
|
||||
compliment: utils.randomCompliment(),
|
||||
challengeId: challenge.id,
|
||||
challengeType: challenge.challengeType,
|
||||
// video challenges
|
||||
video: challenge.challengeSeed[0],
|
||||
// bonfires specific
|
||||
difficulty: Math.floor(+challenge.difficulty),
|
||||
bonfires: challenge,
|
||||
MDNkeys: challenge.MDNlinks,
|
||||
MDNlinks: getMDNLinks(challenge.MDNlinks),
|
||||
// htmls specific
|
||||
environment: utils.whichEnvironment()
|
||||
});
|
||||
})
|
||||
.subscribe(
|
||||
function(data) {
|
||||
@@ -526,6 +474,7 @@ module.exports = function(app) {
|
||||
}
|
||||
|
||||
function challengeMap({ user = {} }, res, next) {
|
||||
let lastCompleted;
|
||||
const daysRunning = moment().diff(new Date('10/15/2014'), 'days');
|
||||
|
||||
// if user
|
||||
@@ -568,7 +517,13 @@ module.exports = function(app) {
|
||||
})
|
||||
.filter(({ name }) => name !== 'Hikes')
|
||||
// turn stream of blocks into a stream of an array
|
||||
.toArray();
|
||||
.toArray()
|
||||
.doOnNext((blocks) => {
|
||||
const lastCompletedBlock = _.findLast(blocks, (block) => {
|
||||
return block.completed === 100;
|
||||
});
|
||||
lastCompleted = lastCompleted && lastCompletedBlock.name || null;
|
||||
});
|
||||
|
||||
Observable.combineLatest(
|
||||
camperCount$,
|
||||
@@ -581,6 +536,7 @@ module.exports = function(app) {
|
||||
blocks,
|
||||
daysRunning,
|
||||
camperCount,
|
||||
lastCompleted,
|
||||
title: "A map of all Free Code Camp's Challenges"
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user