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]) };
|
||||
}
|
||||
|
||||
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) {
|
||||
return actions
|
||||
::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 loadCode = createAction(types.loadCode);
|
||||
export const savedCodeFound = createAction(types.savedCodeFound);
|
||||
export const clearSavedCode = createAction(types.clearSavedCode);
|
||||
|
||||
|
||||
// video challenges
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { Observable } from 'rx';
|
||||
|
||||
import types from './types';
|
||||
import { moveToNextChallenge } from './actions';
|
||||
import {
|
||||
moveToNextChallenge,
|
||||
clearSavedCode
|
||||
} from './actions';
|
||||
|
||||
import { challengeSelector } from './selectors';
|
||||
import { randomCompliment } from '../../../utils/get-words';
|
||||
@ -24,7 +27,8 @@ function postChallenge(url, username, _csrf, challengeInfo) {
|
||||
updateUserChallenge(
|
||||
username,
|
||||
{ ...challengeInfo, lastUpdated, completedDate }
|
||||
)
|
||||
),
|
||||
clearSavedCode()
|
||||
);
|
||||
})
|
||||
.catch(createErrorObservable);
|
||||
|
@ -51,6 +51,7 @@ export default createTypes([
|
||||
'saveCode',
|
||||
'loadCode',
|
||||
'savedCodeFound',
|
||||
'clearSavedCode',
|
||||
|
||||
// video challenges
|
||||
'toggleQuestionView',
|
||||
|
Reference in New Issue
Block a user