fix: clean failed challenges (#37526)

This commit is contained in:
Ahmad Abdolsaheb
2019-11-04 16:50:14 +03:00
committed by mrugesh
parent c2e7809ccd
commit 55a4cadf2a
4 changed files with 81 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import {
} from './';
import postUpdate$ from '../templates/Challenges/utils/postUpdate$';
import { isGoodXHRStatus } from '../templates/Challenges/utils';
import { backEndProject } from '../../utils/challengeTypes';
const key = 'fcc-failed-updates';
@@ -26,6 +27,10 @@ function delay(time = 0, fn) {
return setTimeout(fn, time);
}
// check if backenEndProjects have a solution
const isSubmitable = failure =>
failure.payload.challengeType !== backEndProject || failure.payload.solution;
function failedUpdateEpic(action$, state$) {
const storeUpdates = action$.pipe(
ofType(types.updateFailed),
@@ -45,7 +50,16 @@ function failedUpdateEpic(action$, state$) {
filter(() => store.get(key)),
filter(() => isOnlineSelector(state$.value)),
tap(() => {
const failures = store.get(key) || [];
let failures = store.get(key) || [];
let submitableFailures = failures.filter(isSubmitable);
// delete unsubmitable failed challenges
if (submitableFailures.length !== failures.length) {
store.set(key, submitableFailures);
failures = submitableFailures;
}
let delayTime = 100;
const batch = failures.map((update, i) => {
// we stagger the updates here so we don't hammer the server