diff --git a/src/editors/containers/EditorContainer/hooks.ts b/src/editors/containers/EditorContainer/hooks.ts index 0fa1935de..de37327a2 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 eb9e08ab2..7bc04597a 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 ac7464a82..01583bfd7 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 b380deca4..f3ceed36e 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 775866296..3606f99aa 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 fce98d273..cd9567d40 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 084aa45ca..cb0cd60d3 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 ef98a2ea6..05d471198 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;