From 94b0493521fd160a4c1005c7bdb8f24756a0e3bd Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Wed, 18 Dec 2024 14:21:02 +1100 Subject: [PATCH] fix: clean the editor store when the moda is close --- src/editors/containers/EditorContainer/hooks.ts | 1 - src/editors/containers/EditorContainer/index.tsx | 3 +++ src/editors/data/redux/index.ts | 10 +++++++++- src/editors/data/redux/thunkActions/problem.ts | 1 - src/editors/data/redux/thunkActions/requests.js | 3 +-- src/editors/hooks.ts | 1 - 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/editors/containers/EditorContainer/hooks.ts b/src/editors/containers/EditorContainer/hooks.ts index 0fa1935de3..de37327a23 100644 --- a/src/editors/containers/EditorContainer/hooks.ts +++ b/src/editors/containers/EditorContainer/hooks.ts @@ -40,7 +40,6 @@ export const handleSaveClicked = ({ destination, dispatch, returnFunction, - validateEntry, }); } diff --git a/src/editors/containers/EditorContainer/index.tsx b/src/editors/containers/EditorContainer/index.tsx index eb9e08ab2c..7bc04597a2 100644 --- a/src/editors/containers/EditorContainer/index.tsx +++ b/src/editors/containers/EditorContainer/index.tsx @@ -94,6 +94,7 @@ const EditorContainer: React.FC = ({ const onSave = () => { setSaved(true); handleSave(); + dispatch({ type: 'resetEditor' }); }; // Stops user from navigating away if they have unsaved changes. usePromptIfDirty(() => { @@ -109,6 +110,7 @@ const EditorContainer: React.FC = ({ openCancelConfirmModal(); } else { handleCancel(); + dispatch({ type: 'resetEditor' }); } }; return ( @@ -128,6 +130,7 @@ const EditorContainer: React.FC = ({ if (returnFunction) { closeCancelConfirmModal(); } + dispatch({ type: 'resetEditor' }); }} > diff --git a/src/editors/data/redux/index.ts b/src/editors/data/redux/index.ts index 7758662965..3606f99aa2 100644 --- a/src/editors/data/redux/index.ts +++ b/src/editors/data/redux/index.ts @@ -12,7 +12,7 @@ import { AdvancedProblemType, ProblemType } from '../constants/problem'; export { default as thunkActions } from './thunkActions'; -const rootReducer = combineReducers({ +const editorReducer = combineReducers({ app: app.reducer, requests: requests.reducer, video: video.reducer, @@ -20,6 +20,14 @@ const rootReducer = combineReducers({ game: game.reducer, }); +const rootReducer = (state: any, action: any) => { + if (action.type === 'resetEditor') { + return editorReducer(undefined, action); + } + + return editorReducer(state, action); +}; + const actions = StrictDict({ app: app.actions, requests: requests.actions, diff --git a/src/editors/data/redux/thunkActions/problem.ts b/src/editors/data/redux/thunkActions/problem.ts index fce98d273e..cd9567d407 100644 --- a/src/editors/data/redux/thunkActions/problem.ts +++ b/src/editors/data/redux/thunkActions/problem.ts @@ -59,7 +59,6 @@ export const getDataFromOlx = ({ rawOLX, rawSettings, defaultSettings }) => { }; export const loadProblem = ({ rawOLX, rawSettings, defaultSettings }) => (dispatch) => { - console.debug(rawOLX); if (isBlankProblem({ rawOLX })) { dispatch(actions.problem.setEnableTypeSelection(camelizeKeys(defaultSettings))); } else { diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js index 084aa45cae..cb0cd60d31 100644 --- a/src/editors/data/redux/thunkActions/requests.js +++ b/src/editors/data/redux/thunkActions/requests.js @@ -1,11 +1,10 @@ +import { v4 as uuid4 } from 'uuid'; import { StrictDict, parseLibraryImageData, getLibraryImageAssets } from '../../../utils'; import { RequestKeys } from '../../constants/requests'; import api, { loadImages } from '../../services/cms/api'; import { actions as requestsActions } from '../requests'; import { selectors as appSelectors } from '../app'; -import { v4 as uuid4 } from 'uuid'; - // This 'module' self-import hack enables mocking during tests. // See src/editors/decisions/0005-internal-editor-testability-decisions.md. The whole approach to how hooks are tested diff --git a/src/editors/hooks.ts b/src/editors/hooks.ts index ef98a2ea62..05d471198f 100644 --- a/src/editors/hooks.ts +++ b/src/editors/hooks.ts @@ -71,7 +71,6 @@ export const createBlock = ({ destination, dispatch, returnFunction, - validateEntry, }) => { if (!content) { return;