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 bc3461a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/editors/containers/EditorContainer/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from 'react';
import { useSelector } from 'react-redux';

import { Dispatch } from 'redux';

Check failure on line 4 in src/editors/containers/EditorContainer/hooks.ts

View workflow job for this annotation

GitHub Actions / tests

'Dispatch' is defined but never used
import analyticsEvt from '../../data/constants/analyticsEvt';
import { RequestKeys } from '../../data/constants/requests';
import { selectors } from '../../data/redux';
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
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 bc3461a

Please sign in to comment.