Feature(code-storage): clear code storage on challenge completion
This commit is contained in:
@ -50,6 +50,15 @@ function legacyToFile(code, files, key) {
|
|||||||
return { [key]: updateContents(code, files[key]) };
|
return { [key]: updateContents(code, files[key]) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clearCodeSaga(actions, getState) {
|
||||||
|
return actions
|
||||||
|
::ofType(types.clearSavedCode)
|
||||||
|
.map(() => {
|
||||||
|
const { challengesApp: { id = '' } } = getState();
|
||||||
|
store.clear(id);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
export function saveCodeSaga(actions, getState) {
|
export function saveCodeSaga(actions, getState) {
|
||||||
return actions
|
return actions
|
||||||
::ofType(types.saveCode)
|
::ofType(types.saveCode)
|
||||||
@ -114,4 +123,4 @@ export function loadCodeSaga(actions$, getState, { window, location }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default combineSagas(saveCodeSaga, loadCodeSaga);
|
export default combineSagas(saveCodeSaga, loadCodeSaga, clearCodeSaga);
|
||||||
|
@ -90,6 +90,7 @@ export const moveToNextChallenge = createAction(types.moveToNextChallenge);
|
|||||||
export const saveCode = createAction(types.saveCode);
|
export const saveCode = createAction(types.saveCode);
|
||||||
export const loadCode = createAction(types.loadCode);
|
export const loadCode = createAction(types.loadCode);
|
||||||
export const savedCodeFound = createAction(types.savedCodeFound);
|
export const savedCodeFound = createAction(types.savedCodeFound);
|
||||||
|
export const clearSavedCode = createAction(types.clearSavedCode);
|
||||||
|
|
||||||
|
|
||||||
// video challenges
|
// video challenges
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import { Observable } from 'rx';
|
import { Observable } from 'rx';
|
||||||
|
|
||||||
import types from './types';
|
import types from './types';
|
||||||
import { moveToNextChallenge } from './actions';
|
import {
|
||||||
|
moveToNextChallenge,
|
||||||
|
clearSavedCode
|
||||||
|
} from './actions';
|
||||||
|
|
||||||
import { challengeSelector } from './selectors';
|
import { challengeSelector } from './selectors';
|
||||||
import { randomCompliment } from '../../../utils/get-words';
|
import { randomCompliment } from '../../../utils/get-words';
|
||||||
@ -24,7 +27,8 @@ function postChallenge(url, username, _csrf, challengeInfo) {
|
|||||||
updateUserChallenge(
|
updateUserChallenge(
|
||||||
username,
|
username,
|
||||||
{ ...challengeInfo, lastUpdated, completedDate }
|
{ ...challengeInfo, lastUpdated, completedDate }
|
||||||
)
|
),
|
||||||
|
clearSavedCode()
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(createErrorObservable);
|
.catch(createErrorObservable);
|
||||||
|
@ -51,6 +51,7 @@ export default createTypes([
|
|||||||
'saveCode',
|
'saveCode',
|
||||||
'loadCode',
|
'loadCode',
|
||||||
'savedCodeFound',
|
'savedCodeFound',
|
||||||
|
'clearSavedCode',
|
||||||
|
|
||||||
// video challenges
|
// video challenges
|
||||||
'toggleQuestionView',
|
'toggleQuestionView',
|
||||||
|
Reference in New Issue
Block a user