refactor(client): stop passing around unused data (#57432)

This commit is contained in:
Oliver Eyton-Williams
2024-12-06 14:53:18 +01:00
committed by GitHub
parent 245b486f63
commit 3c48b8dd3f
6 changed files with 13 additions and 12 deletions
+1
View File
@@ -86,6 +86,7 @@ exports.createPages = async function createPages({
blockHashSlug blockHashSlug
} }
id id
isLastChallengeInBlock
order order
required { required {
link link
@@ -219,7 +219,7 @@ export default function completionEpic(action$, state$) {
const state = state$.value; const state = state$.value;
const { const {
nextBlock, isLastChallengeInBlock,
nextChallengePath, nextChallengePath,
challengeType, challengeType,
superBlock, superBlock,
@@ -243,8 +243,7 @@ export default function completionEpic(action$, state$) {
submitter = submitters[submitTypes[challengeType]]; submitter = submitters[submitTypes[challengeType]];
} }
const lastChallengeInBlock = block !== nextBlock; let pathToNavigateTo = isLastChallengeInBlock
let pathToNavigateTo = lastChallengeInBlock
? blockHashSlug ? blockHashSlug
: nextChallengePath; : nextChallengePath;
@@ -254,7 +253,7 @@ export default function completionEpic(action$, state$) {
return submitter(type, state).pipe( return submitter(type, state).pipe(
concat( concat(
of(setIsAdvancing(!lastChallengeInBlock), setIsProcessing(false)) of(setIsAdvancing(!isLastChallengeInBlock), setIsProcessing(false))
), ),
mergeMap(x => mergeMap(x =>
canAllowDonationRequest(state, x) canAllowDonationRequest(state, x)
@@ -23,7 +23,7 @@ const initialState = {
block: '', block: '',
blockHashSlug: '/', blockHashSlug: '/',
id: '', id: '',
nextBlock: '', isLastChallengeInBlock: false,
nextChallengePath: '/', nextChallengePath: '/',
prevChallengePath: '/', prevChallengePath: '/',
challengeType: -1 challengeType: -1
@@ -86,11 +86,6 @@ function getTemplateComponent(challengeType) {
return views[viewTypes[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) { exports.createChallengePages = function (createPage) {
return function ({ node }, index, allChallengeEdges) { return function ({ node }, index, allChallengeEdges) {
const { const {
@@ -104,7 +99,8 @@ exports.createChallengePages = function (createPage) {
required = [], required = [],
template, template,
challengeType, challengeType,
id id,
isLastChallengeInBlock
} = node.challenge; } = node.challenge;
// TODO: challengeType === 7 and isPrivate are the same, right? If so, we // TODO: challengeType === 7 and isPrivate are the same, right? If so, we
// should remove one of them. // should remove one of them.
@@ -124,7 +120,7 @@ exports.createChallengePages = function (createPage) {
isFirstStep: getIsFirstStepInBlock(index, allChallengeEdges), isFirstStep: getIsFirstStepInBlock(index, allChallengeEdges),
template, template,
required, required,
nextBlock: getNextBlock(index, allChallengeEdges), isLastChallengeInBlock: isLastChallengeInBlock,
nextChallengePath: getNextChallengePath(index, allChallengeEdges), nextChallengePath: getNextChallengePath(index, allChallengeEdges),
prevChallengePath: getPrevChallengePath(index, allChallengeEdges), prevChallengePath: getPrevChallengePath(index, allChallengeEdges),
id id
+4
View File
@@ -304,6 +304,9 @@ function generateChallengeCreator(lang, englishPath, i18nPath) {
({ id }) => id === challenge.id ({ id }) => id === challenge.id
); );
const isLastChallengeInBlock =
meta.challengeOrder.length - 1 === challengeOrder;
const isObjectIdFilename = /\/[a-z0-9]{24}\.md$/.test(englishPath); const isObjectIdFilename = /\/[a-z0-9]{24}\.md$/.test(englishPath);
if (isObjectIdFilename) { if (isObjectIdFilename) {
const filename = englishPath.split('/').pop(); const filename = englishPath.split('/').pop();
@@ -348,6 +351,7 @@ function generateChallengeCreator(lang, englishPath, i18nPath) {
challenge.certification = hasDupe ? hasDupe.certification : meta.superBlock; challenge.certification = hasDupe ? hasDupe.certification : meta.superBlock;
challenge.superBlock = meta.superBlock; challenge.superBlock = meta.superBlock;
challenge.challengeOrder = challengeOrder; challenge.challengeOrder = challengeOrder;
challenge.isLastChallengeInBlock = isLastChallengeInBlock;
challenge.isPrivate = challenge.isPrivate || meta.isPrivate; challenge.isPrivate = challenge.isPrivate || meta.isPrivate;
challenge.required = (meta.required || []).concat(challenge.required || []); challenge.required = (meta.required || []).concat(challenge.required || []);
challenge.template = meta.template; challenge.template = meta.template;
+1
View File
@@ -180,6 +180,7 @@ const schema = Joi.object()
'Euler', 'Euler',
'Rosetta' 'Rosetta'
), ),
isLastChallengeInBlock: Joi.boolean().required(),
videoUrl: Joi.string().allow(''), videoUrl: Joi.string().allow(''),
fillInTheBlank: Joi.object().keys({ fillInTheBlank: Joi.object().keys({
sentence: Joi.string().required(), sentence: Joi.string().required(),