Skip to content

Commit

Permalink
fix: clean the editor store when the moda is close
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Dec 18, 2024
1 parent 7b0b9c8 commit 6af6ee7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/editors/containers/EditorContainer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const handleSaveClicked = ({
destination,
dispatch,
returnFunction,
validateEntry,
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/editors/containers/EditorContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const EditorContainer: React.FC<Props> = ({
const onSave = () => {
setSaved(true);
handleSave();
dispatch({ type: 'resetEditor' });
};
// Stops user from navigating away if they have unsaved changes.
usePromptIfDirty(() => {
Expand All @@ -109,6 +110,7 @@ const EditorContainer: React.FC<Props> = ({
openCancelConfirmModal();
} else {
handleCancel();
dispatch({ type: 'resetEditor' });
}
};
return (
Expand All @@ -128,6 +130,7 @@ const EditorContainer: React.FC<Props> = ({
if (returnFunction) {
closeCancelConfirmModal();
}
dispatch({ type: 'resetEditor' });
}}
>
<FormattedMessage {...messages.okButtonLabel} />
Expand Down
6 changes: 3 additions & 3 deletions src/editors/containers/VideoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const VideoEditor: React.FC<EditorComponent> = ({
}) => {
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,
Expand All @@ -37,7 +37,7 @@ const VideoEditor: React.FC<EditorComponent> = ({
returnFunction={returnFunction}
validateEntry={validateEntry}
>
{studioViewFinished ? (
{(isCreateBlock || studioViewFinished) ? (
<div className="video-editor">
<VideoEditorModal {...{ isLibrary }} />
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/editors/data/redux/app/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
Expand All @@ -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));
});
});
Expand Down
10 changes: 9 additions & 1 deletion src/editors/data/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ 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,
problem: problem.reducer,
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,
Expand Down
1 change: 0 additions & 1 deletion src/editors/data/redux/thunkActions/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/editors/data/redux/thunkActions/requests.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/editors/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const createBlock = ({
destination,
dispatch,
returnFunction,
validateEntry,
}) => {
if (!content) {
return;
Expand Down

0 comments on commit 6af6ee7

Please sign in to comment.