From 1e82165ed2afc56a8a81e8eb5ee4432cab7a64d5 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Tue, 8 Sep 2015 21:15:18 -0700 Subject: [PATCH 01/10] add learn button back in and fix redirect loop associated with it --- server/boot/challenge.js | 2 +- server/views/partials/navbar.jade | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server/boot/challenge.js b/server/boot/challenge.js index ae0400d86a..94412a226e 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -101,7 +101,7 @@ module.exports = function(app) { const send200toNonUser = ifNoUserSend(true); const redirectNonUser = ifNoUserRedirectTo( - '/challenges/learn-how-free-code-camp-works' + '/map' ); router.post( diff --git a/server/views/partials/navbar.jade b/server/views/partials/navbar.jade index d7861a224d..9592bd58b3 100644 --- a/server/views/partials/navbar.jade +++ b/server/views/partials/navbar.jade @@ -7,6 +7,8 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height img.img-responsive.nav-logo(src='https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg', alt='learn to code javascript at Free Code Camp logo') .collapse.navbar-collapse ul.nav.navbar-nav.navbar-right.hamburger-dropdown + li + a(href='/challenges') Learn li a(href='/map') Map li From f0a49246710d43c7aba325217ac12c12635fd129 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Tue, 8 Sep 2015 21:45:53 -0700 Subject: [PATCH 02/10] start refactoring next challenge logic --- client/commonFramework.js | 2 +- client/main.js | 8 ++++---- server/boot/challenge.js | 7 +------ server/views/partials/challenge-modals.jade | 1 + 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/client/commonFramework.js b/client/commonFramework.js index be5be4533c..0d2a4d9894 100644 --- a/client/commonFramework.js +++ b/client/commonFramework.js @@ -457,7 +457,7 @@ function showCompletion() { }, function(res) { if (res) { - window.location = '/challenges/next-challenge'; + window.location = '/challenges/next-challenge?id=' + challenge_Id; } } ); diff --git a/client/main.js b/client/main.js index bbd69857d0..fe46956142 100644 --- a/client/main.js +++ b/client/main.js @@ -141,7 +141,7 @@ $(document).ready(function() { }).success( function(res) { if (res) { - window.location.href = '/challenges/next-challenge'; + window.location.href = '/challenges/next-challenge?id=' + challenge_Id; } }).fail( function() { @@ -164,7 +164,7 @@ $(document).ready(function() { } }).success( function() { - window.location.href = '/challenges/next-challenge'; + window.location.href = '/challenges/next-challenge?id=' + challenge_Id; }).fail( function() { window.location.href = '/challenges'; @@ -187,13 +187,13 @@ $(document).ready(function() { verified: false } }).success(function() { - window.location.href = '/challenges/next-challenge'; + window.location.href = '/challenges/next-challenge?id=' + challenge_Id; }).fail(function() { window.location.replace(window.location.href); }); break; case challengeTypes.BONFIRE: - window.location.href = '/challenges/next-challenge'; + window.location.href = '/challenges/next-challenge?id=' + challenge_Id; default: break; } diff --git a/server/boot/challenge.js b/server/boot/challenge.js index 94412a226e..4c3c261d47 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -142,9 +142,7 @@ module.exports = function(app) { 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,9 +197,6 @@ module.exports = function(app) { nextChallengeName = nextChallenge.dashedName; return nextChallengeName; }) - .flatMap(() => { - return saveUser(req.user); - }) .subscribe( function() {}, next, diff --git a/server/views/partials/challenge-modals.jade b/server/views/partials/challenge-modals.jade index cd0339cc08..24805a953b 100644 --- a/server/views/partials/challenge-modals.jade +++ b/server/views/partials/challenge-modals.jade @@ -47,3 +47,4 @@ h3 This will restore your code editor to its original state. 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. From 184ba1fa374bc5150dfa713027bf7366114d97a3 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 8 Sep 2015 22:18:25 -0700 Subject: [PATCH 03/10] add challengeId to localStorage remove unneeded current challenge route --- server/boot/challenge.js | 34 --------------------- server/views/partials/challenge-modals.jade | 3 ++ 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/server/boot/challenge.js b/server/boot/challenge.js index 4c3c261d47..cac6d0a867 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -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); diff --git a/server/views/partials/challenge-modals.jade b/server/views/partials/challenge-modals.jade index 24805a953b..5776c8d7ce 100644 --- a/server/views/partials/challenge-modals.jade +++ b/server/views/partials/challenge-modals.jade @@ -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); + } From 9cc862e9a680c8b0eb52915b485eb8c18a8b0a9a Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 8 Sep 2015 22:31:20 -0700 Subject: [PATCH 04/10] add learn button functionality learn button looks for current challenge in localStorage if not present sends user to map --- server/views/partials/navbar.jade | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server/views/partials/navbar.jade b/server/views/partials/navbar.jade index 9592bd58b3..bc6a85ce20 100644 --- a/server/views/partials/navbar.jade +++ b/server/views/partials/navbar.jade @@ -8,7 +8,7 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height .collapse.navbar-collapse ul.nav.navbar-nav.navbar-right.hamburger-dropdown li - a(href='/challenges') Learn + a.learn-btn(href='#') Learn li a(href='/map') Map li @@ -34,3 +34,16 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height .hidden-xs.hidden-sm a(href='/account') img.profile-picture.float-right(src='#{user.picture}') +script. + $(document).ready(function() { + $('.learn-btn').click(function(e) { + var challengeId = null; + e.preventDefault(); + if (typeof localStorage !== 'undefined') { + challengeId = localStorage.getItem('currentChallenge'); + } + window.location = challengeId ? + '/challenges/next-challenge?id=' + challengeId : + '/map'; + }); + }); From b2d04ec7c501d71901622dba5a24a0babff6fb8c Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 8 Sep 2015 22:41:03 -0700 Subject: [PATCH 05/10] remove save to user on return individual user --- server/boot/challenge.js | 57 ++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/server/boot/challenge.js b/server/boot/challenge.js index cac6d0a867..58c4371d97 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -246,40 +246,29 @@ module.exports = function(app) { return Observable.just('/challenges/' + dasherize(challenge.name)); } - 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, + 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) { From b228cc064cbe1ff460e4ea895407c55cde9a9173 Mon Sep 17 00:00:00 2001 From: Aryan Jabbari Date: Sat, 5 Sep 2015 20:10:14 -0400 Subject: [PATCH 06/10] Clarifies instructions for shift() challenge; closes #1875 --- seed/challenges/basic-javascript.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed/challenges/basic-javascript.json b/seed/challenges/basic-javascript.json index 6b77ebac56..9dccea8951 100644 --- a/seed/challenges/basic-javascript.json +++ b/seed/challenges/basic-javascript.json @@ -604,7 +604,7 @@ "difficulty": "9.9817", "description": [ "pop() always removes the last element of an array. What if you want to remove the first? That's where .shift() comes in.", - "Take the myArray array and shift() the first value off of it." + "Take the myArray array and shift() the first value off of it. Set myRemoved to the first value of myArray using shift()." ], "tests": [ "assert((function(d){if(d[0] == 23 && d[1][0] == 'dog' && d[1][1] == 3 && d[2] == undefined){return true;}else{return false;}})(myArray), 'myArray should only have the last two values left([23, [\"dog\", 3]])');", From b1ceff3ee27dba9c84c12bb5d547544ca69bd58e Mon Sep 17 00:00:00 2001 From: Aniruddh Agarwal Date: Wed, 9 Sep 2015 10:02:08 +0800 Subject: [PATCH 07/10] Fixed typo in Basic Javascript Waypoint Waypoint 'Sift through Text with Regular Expressions' had `...` in its description instead of `.`. Made the required changes. closes #3169 --- seed/challenges/basic-javascript.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed/challenges/basic-javascript.json b/seed/challenges/basic-javascript.json index 9dccea8951..b7c5ea2dc2 100644 --- a/seed/challenges/basic-javascript.json +++ b/seed/challenges/basic-javascript.json @@ -1022,7 +1022,7 @@ "g means that we want to search the entire string for this pattern instead of just the first match.", "i means that we want to ignore the case (uppercase or lowercase) when searching for the pattern.", "Regular expressions are written by surrounding the pattern with a / symbol.", - "Let's try selecting all the occurrences of the word and in the string George Boole and Alan Turing went to the shop and got some milk. We can do this by replacing the ... part of our regular expression with the current regular expression with the word and." + "Let's try selecting all the occurrences of the word and in the string George Boole and Alan Turing went to the shop and got some milk. We can do this by replacing the . part of our regular expression with the current regular expression with the word and." ], "tests":[ "assert(test==2, 'Your regular expression should find two occurrences of the word and');", From dccfcfeb2eabb2a4a5d313a7206833b55b097783 Mon Sep 17 00:00:00 2001 From: Aniruddh Agarwal Date: Wed, 9 Sep 2015 11:52:21 +0800 Subject: [PATCH 08/10] Fix typo in basic-javascript waypoint Waypoint 'Invert Regular Expression Matches with JavaScript' had a semi-colon in the description for the regex example which is not needed. closes #3148 --- seed/challenges/basic-javascript.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed/challenges/basic-javascript.json b/seed/challenges/basic-javascript.json index b7c5ea2dc2..b42dcf7db4 100644 --- a/seed/challenges/basic-javascript.json +++ b/seed/challenges/basic-javascript.json @@ -1109,7 +1109,7 @@ "title": "Invert Regular Expression Matches with JavaScript", "difficulty":"9.987", "description":[ - "Use /\\S/gi; to match everything that isn't a space in the string.", + "Use /\\S/gi to match everything that isn't a space in the string.", "You can invert any match by using the uppercase version of the selector \\s versus \\S for example." ], "tests":[ From 05864b4813204f13340e05f14702d6e951ea5b7e Mon Sep 17 00:00:00 2001 From: Aniruddh Agarwal Date: Wed, 9 Sep 2015 11:44:53 +0800 Subject: [PATCH 09/10] Fixed wording error in HTML/CSS waypoint Waypoint 'Add Different Padding to Each Side of an Element' had a small wording error: the tests were missing `the` closes #3130 --- seed/challenges/html5-and-css.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/seed/challenges/html5-and-css.json b/seed/challenges/html5-and-css.json index 29bb0cae22..f67197acf5 100644 --- a/seed/challenges/html5-and-css.json +++ b/seed/challenges/html5-and-css.json @@ -2842,10 +2842,10 @@ "Give the green box a padding of 40px on its top and left side, but only 20px on its bottom and right side." ], "tests": [ - "assert($(\".green-box\").css(\"padding-top\") === \"40px\", 'Your green-box class should give the top of elements 40px of padding.')", - "assert($(\".green-box\").css(\"padding-left\") === \"40px\", 'Your green-box class should give the left of elements 40px of padding.')", - "assert($(\".green-box\").css(\"padding-right\") === \"20px\", 'Your green-box class should give the right of elements 20px of padding.')", - "assert($(\".green-box\").css(\"padding-bottom\") === \"20px\", 'Your green-box class should give the bottom of elements 20px of padding.')" + "assert($(\".green-box\").css(\"padding-top\") === \"40px\", 'Your green-box class should give the top of the elements 40px of padding.')", + "assert($(\".green-box\").css(\"padding-left\") === \"40px\", 'Your green-box class should give the left of the elements 40px of padding.')", + "assert($(\".green-box\").css(\"padding-right\") === \"20px\", 'Your green-box class should give the right of the elements 20px of padding.')", + "assert($(\".green-box\").css(\"padding-bottom\") === \"20px\", 'Your green-box class should give the bottom of the elements 20px of padding.')" ], "challengeSeed": [ "