diff --git a/client/gatsby-node.js b/client/gatsby-node.js index 3e405884b09..9526430448b 100644 --- a/client/gatsby-node.js +++ b/client/gatsby-node.js @@ -86,6 +86,7 @@ exports.createPages = async function createPages({ blockHashSlug } id + isLastChallengeInBlock order required { link diff --git a/client/src/templates/Challenges/redux/completion-epic.js b/client/src/templates/Challenges/redux/completion-epic.js index 79e2116e58b..fb200721bf6 100644 --- a/client/src/templates/Challenges/redux/completion-epic.js +++ b/client/src/templates/Challenges/redux/completion-epic.js @@ -219,7 +219,7 @@ export default function completionEpic(action$, state$) { const state = state$.value; const { - nextBlock, + isLastChallengeInBlock, nextChallengePath, challengeType, superBlock, @@ -243,8 +243,7 @@ export default function completionEpic(action$, state$) { submitter = submitters[submitTypes[challengeType]]; } - const lastChallengeInBlock = block !== nextBlock; - let pathToNavigateTo = lastChallengeInBlock + let pathToNavigateTo = isLastChallengeInBlock ? blockHashSlug : nextChallengePath; @@ -254,7 +253,7 @@ export default function completionEpic(action$, state$) { return submitter(type, state).pipe( concat( - of(setIsAdvancing(!lastChallengeInBlock), setIsProcessing(false)) + of(setIsAdvancing(!isLastChallengeInBlock), setIsProcessing(false)) ), mergeMap(x => canAllowDonationRequest(state, x) diff --git a/client/src/templates/Challenges/redux/index.js b/client/src/templates/Challenges/redux/index.js index 0e331c87491..a24ffab0d3a 100644 --- a/client/src/templates/Challenges/redux/index.js +++ b/client/src/templates/Challenges/redux/index.js @@ -23,7 +23,7 @@ const initialState = { block: '', blockHashSlug: '/', id: '', - nextBlock: '', + isLastChallengeInBlock: false, nextChallengePath: '/', prevChallengePath: '/', challengeType: -1 diff --git a/client/utils/gatsby/challenge-page-creator.js b/client/utils/gatsby/challenge-page-creator.js index 3e733405d54..480ea5c1c29 100644 --- a/client/utils/gatsby/challenge-page-creator.js +++ b/client/utils/gatsby/challenge-page-creator.js @@ -86,11 +86,6 @@ function getTemplateComponent(challengeType) { return views[viewTypes[challengeType]]; } -function getNextBlock(id, edges) { - const next = edges[id + 1]; - return next ? next.node.challenge.block : null; -} - exports.createChallengePages = function (createPage) { return function ({ node }, index, allChallengeEdges) { const { @@ -104,7 +99,8 @@ exports.createChallengePages = function (createPage) { required = [], template, challengeType, - id + id, + isLastChallengeInBlock } = node.challenge; // TODO: challengeType === 7 and isPrivate are the same, right? If so, we // should remove one of them. @@ -124,7 +120,7 @@ exports.createChallengePages = function (createPage) { isFirstStep: getIsFirstStepInBlock(index, allChallengeEdges), template, required, - nextBlock: getNextBlock(index, allChallengeEdges), + isLastChallengeInBlock: isLastChallengeInBlock, nextChallengePath: getNextChallengePath(index, allChallengeEdges), prevChallengePath: getPrevChallengePath(index, allChallengeEdges), id diff --git a/curriculum/get-challenges.js b/curriculum/get-challenges.js index a26309f5c5d..148a2b66d70 100644 --- a/curriculum/get-challenges.js +++ b/curriculum/get-challenges.js @@ -304,6 +304,9 @@ function generateChallengeCreator(lang, englishPath, i18nPath) { ({ id }) => id === challenge.id ); + const isLastChallengeInBlock = + meta.challengeOrder.length - 1 === challengeOrder; + const isObjectIdFilename = /\/[a-z0-9]{24}\.md$/.test(englishPath); if (isObjectIdFilename) { const filename = englishPath.split('/').pop(); @@ -348,6 +351,7 @@ function generateChallengeCreator(lang, englishPath, i18nPath) { challenge.certification = hasDupe ? hasDupe.certification : meta.superBlock; challenge.superBlock = meta.superBlock; challenge.challengeOrder = challengeOrder; + challenge.isLastChallengeInBlock = isLastChallengeInBlock; challenge.isPrivate = challenge.isPrivate || meta.isPrivate; challenge.required = (meta.required || []).concat(challenge.required || []); challenge.template = meta.template; diff --git a/curriculum/schema/challenge-schema.js b/curriculum/schema/challenge-schema.js index f6b8ca776ef..0e17934897e 100644 --- a/curriculum/schema/challenge-schema.js +++ b/curriculum/schema/challenge-schema.js @@ -180,6 +180,7 @@ const schema = Joi.object() 'Euler', 'Rosetta' ), + isLastChallengeInBlock: Joi.boolean().required(), videoUrl: Joi.string().allow(''), fillInTheBlank: Joi.object().keys({ sentence: Joi.string().required(),