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

This commit is contained in:
Shaun Hamilton
2021-08-13 19:15:50 +01:00
committed by GitHub
parent 4190e2264d
commit e98d3dd3da

View File

@ -60,9 +60,15 @@ function legacyToFile(code, challengeFiles, fileKey) {
} }
function isFilesAllPoly(challengeFiles) { function isFilesAllPoly(challengeFiles) {
// TODO: figure out how challengeFiles might be null/not have .every as a if (Array.isArray(challengeFiles)) {
// function return challengeFiles?.every(file => isPoly(file));
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$) { function clearCodeEpic(action$, state$) {
@ -134,9 +140,16 @@ function loadCodeEpic(action$, state$) {
const codeFound = getCode(id); const codeFound = getCode(id);
if (codeFound && isFilesAllPoly(codeFound)) { if (codeFound && isFilesAllPoly(codeFound)) {
finalFiles = challengeFiles.reduce((challengeFiles, challengeFile) => { finalFiles = challengeFiles.reduce((challengeFiles, challengeFile) => {
const foundChallengeFile = codeFound.find( let foundChallengeFile = {};
x => x.fileKey === challengeFile.fileKey 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; const isCodeFound = Object.keys(foundChallengeFile).length > 0;
return [ return [
...challengeFiles, ...challengeFiles,