fix(client): handle final project submission (#50818)

Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
This commit is contained in:
Oliver Eyton-Williams
2023-07-04 22:04:45 +02:00
committed by GitHub
parent e526f1856a
commit 13110a9665
6 changed files with 62 additions and 55 deletions
+16 -48
View File
@@ -53,21 +53,21 @@ const views = {
// quiz: Quiz
};
function getIsFirstStep(_node, index, nodeArray) {
const current = nodeArray[index];
const previous = nodeArray[index - 1];
function getIsFirstStepInBlock(id, edges) {
const current = edges[id];
const previous = edges[id - 1];
if (!previous) return true;
return previous.node.challenge.block !== current.node.challenge.block;
}
function getNextChallengePath(_node, index, nodeArray) {
const next = nodeArray[index + 1];
function getNextChallengePath(id, edges) {
const next = edges[id + 1];
return next ? next.node.challenge.fields.slug : null;
}
function getPrevChallengePath(_node, index, nodeArray) {
const prev = nodeArray[index - 1];
function getPrevChallengePath(id, edges) {
const prev = edges[id - 1];
return prev ? prev.node.challenge.fields.slug : null;
}
@@ -75,29 +75,9 @@ function getTemplateComponent(challengeType) {
return views[viewTypes[challengeType]];
}
function getNextChallengeMeta(_node, index, nodeArray) {
const next = nodeArray[index + 1];
if (next) {
const { superBlock, block } = next.node.challenge;
return {
superBlock,
block,
blockHashSlug: createBlockHashSlug(_node)
};
}
return null;
}
function createBlockHashSlug(_node) {
if (_node) {
const {
block,
fields: { slug }
} = _node;
const re = new RegExp(`${block}.*`);
return slug.replace(re, `#${block}`);
}
return null;
function getNextBlock(id, edges) {
const next = edges[id + 1];
return next ? next.node.challenge.block : null;
}
exports.createChallengePages = function (createPage) {
@@ -107,7 +87,7 @@ exports.createChallengePages = function (createPage) {
certification,
superBlock,
block,
fields: { slug },
fields: { slug, blockHashSlug },
required = [],
template,
challengeType,
@@ -121,29 +101,17 @@ exports.createChallengePages = function (createPage) {
component: getTemplateComponent(challengeType),
context: {
challengeMeta: {
blockHashSlug: createBlockHashSlug(challenge),
blockHashSlug,
dashedName,
certification,
superBlock,
block,
isFirstStep: getIsFirstStep(challenge, index, allChallengeEdges),
isFirstStep: getIsFirstStepInBlock(index, allChallengeEdges),
template,
required,
nextChallengeMeta: getNextChallengeMeta(
challenge,
index,
allChallengeEdges
),
nextChallengePath: getNextChallengePath(
challenge,
index,
allChallengeEdges
),
prevChallengePath: getPrevChallengePath(
challenge,
index,
allChallengeEdges
),
nextBlock: getNextBlock(index, allChallengeEdges),
nextChallengePath: getNextChallengePath(index, allChallengeEdges),
prevChallengePath: getPrevChallengePath(index, allChallengeEdges),
id
},
projectPreview: getProjectPreviewConfig(challenge, allChallengeEdges),