From 6af6ee7ac8ad2dee0a12b6c4cae318d42bcacc7c Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Wed, 18 Dec 2024 16:24:37 +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/containers/VideoEditor/index.tsx | 6 +++--- src/editors/data/redux/app/selectors.test.ts | 10 +++++----- 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 - 8 files changed, 21 insertions(+), 14 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/containers/VideoEditor/index.tsx b/src/editors/containers/VideoEditor/index.tsx index ac7464a826..01583bfd7d 100644 --- a/src/editors/containers/VideoEditor/index.tsx +++ b/src/editors/containers/VideoEditor/index.tsx @@ -20,10 +20,10 @@ const VideoEditor: React.FC = ({ }) => { const intl = useIntl(); const studioViewFinished = useSelector( - (state) => selectors.app.isCreateBlock(state) - || selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }), + (state) => selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }), ); const isLibrary = useSelector(selectors.app.isLibrary) as boolean; + const isCreateBlock = useSelector(selectors.app.isCreateBlock) as boolean; const { error, validateEntry, @@ -37,7 +37,7 @@ const VideoEditor: React.FC = ({ returnFunction={returnFunction} validateEntry={validateEntry} > - {studioViewFinished ? ( + {(isCreateBlock || studioViewFinished) ? (
diff --git a/src/editors/data/redux/app/selectors.test.ts b/src/editors/data/redux/app/selectors.test.ts index b380deca4f..f3ceed36e5 100644 --- a/src/editors/data/redux/app/selectors.test.ts +++ b/src/editors/data/redux/app/selectors.test.ts @@ -98,8 +98,8 @@ describe('app selectors unit tests', () => { }; [ - [[null, truthy.blockValue, true] as [any, any, any], true] as const, - [[null, null, true] as [any, any, any], false] as const, + [[null, truthy.blockValue, true, false] as [any, any, any, any], true] as const, + [[null, null, true, false] as [any, any, any, any], false] as const, ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); }); }); @@ -112,9 +112,9 @@ describe('app selectors unit tests', () => { }; [ - [[null, truthy.blockValue, false] as [any, any, any], false] as const, - [[truthy.unitUrl, null, false] as [any, any, any], false] as const, - [[truthy.unitUrl, truthy.blockValue, false] as [any, any, any], true] as const, + [[null, truthy.blockValue, false, false] as [any, any, any, any], false] as const, + [[truthy.unitUrl, null, false, false] as [any, any, any, any], false] as const, + [[truthy.unitUrl, truthy.blockValue, false, false] as [any, any, any, any], true] as const, ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); }); }); 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;