mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(client): provide return types for get-completion-percentage (#49458)
fix: provide return types I also moved the undefined check closer to the source, so it's clearer what is missing
This commit is contained in:
@@ -94,30 +94,25 @@ export const challengeDataSelector = state => {
|
||||
export const currentBlockIdsSelector = state => {
|
||||
const { block, certification, challengeType } = challengeMetaSelector(state);
|
||||
const allChallengesInfo = allChallengesInfoSelector(state);
|
||||
const currentBlockIds = getCurrentBlockIds(
|
||||
|
||||
return getCurrentBlockIds(
|
||||
allChallengesInfo,
|
||||
block,
|
||||
certification,
|
||||
challengeType
|
||||
);
|
||||
|
||||
if (!currentBlockIds) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return currentBlockIds;
|
||||
};
|
||||
|
||||
export const completedChallengesInBlockSelector = state => {
|
||||
const completedChallengesIds = completedChallengesIdsSelector(state);
|
||||
const currentBlockIds = currentBlockIdsSelector(state);
|
||||
const { id } = challengeMetaSelector(state);
|
||||
const completedChallengesInBlock = getCompletedChallengesInBlock(
|
||||
|
||||
return getCompletedChallengesInBlock(
|
||||
completedChallengesIds,
|
||||
currentBlockIds,
|
||||
id
|
||||
);
|
||||
return completedChallengesInBlock;
|
||||
};
|
||||
|
||||
export const completedPercentageSelector = state => {
|
||||
|
||||
@@ -23,7 +23,7 @@ export function getCompletedChallengesInBlock(
|
||||
completedChallengesIds: string[],
|
||||
currentBlockIds: string[],
|
||||
currentChallengeId: string
|
||||
) {
|
||||
): number {
|
||||
const oldCompletionCount = completedChallengesIds.filter(challengeId =>
|
||||
currentBlockIds.includes(challengeId)
|
||||
).length;
|
||||
@@ -39,13 +39,14 @@ export const getCurrentBlockIds = (
|
||||
block: string,
|
||||
certification: string,
|
||||
challengeType: number
|
||||
) => {
|
||||
): string[] => {
|
||||
const { challengeEdges, certificateNodes } = allChallengesInfo;
|
||||
const currentCertificateIds = certificateNodes
|
||||
.filter(
|
||||
node => dasherize(node.challenge.certification) === certification
|
||||
)[0]
|
||||
?.challenge.tests.map(test => test.id);
|
||||
const currentCertificateIds =
|
||||
certificateNodes
|
||||
.filter(
|
||||
node => dasherize(node.challenge.certification) === certification
|
||||
)[0]
|
||||
?.challenge.tests.map(test => test.id) ?? [];
|
||||
const currentBlockIds = challengeEdges
|
||||
.filter(edge => edge.node.challenge.block === block)
|
||||
.map(edge => edge.node.challenge.id);
|
||||
|
||||
Reference in New Issue
Block a user