add challengeId to localStorage
remove unneeded current challenge route
This commit is contained in:
@ -131,12 +131,6 @@ module.exports = function(app) {
|
||||
|
||||
router.get('/challenges/:challengeName', returnIndividualChallenge);
|
||||
|
||||
router.get(
|
||||
'/challenges/',
|
||||
redirectNonUser,
|
||||
returnCurrentChallenge
|
||||
);
|
||||
|
||||
app.use(router);
|
||||
|
||||
function returnNextChallenge(req, res, next) {
|
||||
@ -218,34 +212,6 @@ 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 unDashedName = unDasherize(origChallengeName);
|
||||
|
@ -48,3 +48,6 @@
|
||||
a.btn.btn-lg.btn-info.btn-block#reset-button(href='#', data-dismiss='modal', aria-hidden='true') Clear my code
|
||||
a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
|
||||
script.
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem('currentChallenge', challenge_Id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user