Files
freeCodeCamp/client/utils/gatsby/challenge-page-creator.js
Vishwasa Navada K 9abc5f66ba feat(client): ts-migrate multiple files (#43262)
* feat(client): ts-migrate rename files

* feat(client): ts-migrate client/src/templates/Introduction/*

* feat(client): ts-migrate client/src/components/formHelpers/form*

* fix: import

* Update client/src/components/formHelpers/form-validators.tsx

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update client/src/components/formHelpers/form-fields.tsx

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update client/src/components/formHelpers/form-fields.tsx

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* fix: types in client/src/components/formHelpers/index.tsx

* fix: types in client/src/templates/Introduction/super-block-intro.tsx

* fix: types in client/src/components/formHelpers/*

* fix: signInLoading and value types

* Update client/src/templates/Introduction/super-block-intro.tsx

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* Update client/src/components/formHelpers/index.tsx

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* Update client/src/components/formHelpers/index.tsx

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* Update client/src/components/formHelpers/index.tsx

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* chore(deps): update dependency rollup to v2.58.1

* fix: rename variables and fix imports for ts-migrate

* fix: remove `Type` suffix from the type definition.

* Update client/src/components/formHelpers/form.tsx

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-10-25 18:45:36 +01:00

127 lines
2.7 KiB
JavaScript

const path = require('path');
const { dasherize } = require('../../../utils/slugs');
const { viewTypes } = require('../challenge-types');
const backend = path.resolve(
__dirname,
'../../src/templates/Challenges/projects/backend/Show.tsx'
);
const classic = path.resolve(
__dirname,
'../../src/templates/Challenges/classic/show.tsx'
);
const frontend = path.resolve(
__dirname,
'../../src/templates/Challenges/projects/frontend/Show.tsx'
);
const codeally = path.resolve(
__dirname,
'../../src/templates/Challenges/codeally/show.tsx'
);
const intro = path.resolve(
__dirname,
'../../src/templates/Introduction/intro.tsx'
);
const superBlockIntro = path.resolve(
__dirname,
'../../src/templates/Introduction/super-block-intro.tsx'
);
const video = path.resolve(
__dirname,
'../../src/templates/Challenges/video/Show.tsx'
);
const views = {
backend,
classic,
modern: classic,
frontend,
video,
codeally
// quiz: Quiz
};
function getNextChallengePath(_node, index, nodeArray) {
const next = nodeArray[index + 1];
return next ? next.node.fields.slug : '/learn';
}
function getPrevChallengePath(_node, index, nodeArray) {
const prev = nodeArray[index - 1];
return prev ? prev.node.fields.slug : '/learn';
}
function getTemplateComponent(challengeType) {
return views[viewTypes[challengeType]];
}
exports.createChallengePages = function (createPage) {
return function ({ node }, index, thisArray) {
const {
superBlock,
block,
fields: { slug },
required = [],
template,
challengeType,
id
} = node;
// TODO: challengeType === 7 and isPrivate are the same, right? If so, we
// should remove one of them.
createPage({
path: slug,
component: getTemplateComponent(challengeType),
context: {
challengeMeta: {
superBlock,
block,
template,
required,
nextChallengePath: getNextChallengePath(node, index, thisArray),
prevChallengePath: getPrevChallengePath(node, index, thisArray),
id
},
slug
}
});
};
};
exports.createBlockIntroPages = function (createPage) {
return function (edge) {
const {
fields: { slug },
frontmatter: { block }
} = edge.node;
createPage({
path: slug,
component: intro,
context: {
block: dasherize(block),
slug
}
});
};
};
exports.createSuperBlockIntroPages = function (createPage) {
return function (edge) {
const {
fields: { slug },
frontmatter: { superBlock }
} = edge.node;
createPage({
path: slug,
component: superBlockIntro,
context: {
superBlock,
slug
}
});
};
};