fix(client): allow old local-storage code (#43196)

pull/43197/head
Shaun Hamilton 2021-08-13 19:15:50 +01:00 committed by GitHub
parent 4190e2264d
commit e98d3dd3da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 6 deletions

View File

@ -60,9 +60,15 @@ function legacyToFile(code, challengeFiles, fileKey) {
}
function isFilesAllPoly(challengeFiles) {
// TODO: figure out how challengeFiles might be null/not have .every as a
// function
return challengeFiles?.every(file => isPoly(file));
if (Array.isArray(challengeFiles)) {
return challengeFiles?.every(file => isPoly(file));
} else {
// TODO: After sufficient time, remove parsing of old code-storage format
// This was pushed to production with https://github.com/freeCodeCamp/freeCodeCamp/pull/43023
return Object.keys(challengeFiles)
.map(key => challengeFiles[key])
.every(file => isPoly(file));
}
}
function clearCodeEpic(action$, state$) {
@ -134,9 +140,16 @@ function loadCodeEpic(action$, state$) {
const codeFound = getCode(id);
if (codeFound && isFilesAllPoly(codeFound)) {
finalFiles = challengeFiles.reduce((challengeFiles, challengeFile) => {
const foundChallengeFile = codeFound.find(
x => x.fileKey === challengeFile.fileKey
);
let foundChallengeFile = {};
if (Array.isArray(codeFound)) {
foundChallengeFile = codeFound.find(
x => x.fileKey === challengeFile.fileKey
);
} else {
// TODO: After sufficient time, remove parsing of old code-storage format
// This was pushed to production with https://github.com/freeCodeCamp/freeCodeCamp/pull/43023
foundChallengeFile = codeFound[challengeFile.fileKey];
}
const isCodeFound = Object.keys(foundChallengeFile).length > 0;
return [
...challengeFiles,