Skip to content

Commit 6af6ee7

Browse files
committed
fix: clean the editor store when the moda is close
1 parent 7b0b9c8 commit 6af6ee7

File tree

8 files changed

+21
-14
lines changed

8 files changed

+21
-14
lines changed

src/editors/containers/EditorContainer/hooks.ts

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const handleSaveClicked = ({
4040
destination,
4141
dispatch,
4242
returnFunction,
43-
validateEntry,
4443
});
4544
}
4645

src/editors/containers/EditorContainer/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const EditorContainer: React.FC<Props> = ({
9494
const onSave = () => {
9595
setSaved(true);
9696
handleSave();
97+
dispatch({ type: 'resetEditor' });
9798
};
9899
// Stops user from navigating away if they have unsaved changes.
99100
usePromptIfDirty(() => {
@@ -109,6 +110,7 @@ const EditorContainer: React.FC<Props> = ({
109110
openCancelConfirmModal();
110111
} else {
111112
handleCancel();
113+
dispatch({ type: 'resetEditor' });
112114
}
113115
};
114116
return (
@@ -128,6 +130,7 @@ const EditorContainer: React.FC<Props> = ({
128130
if (returnFunction) {
129131
closeCancelConfirmModal();
130132
}
133+
dispatch({ type: 'resetEditor' });
131134
}}
132135
>
133136
<FormattedMessage {...messages.okButtonLabel} />

src/editors/containers/VideoEditor/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const VideoEditor: React.FC<EditorComponent> = ({
2020
}) => {
2121
const intl = useIntl();
2222
const studioViewFinished = useSelector(
23-
(state) => selectors.app.isCreateBlock(state)
24-
|| selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }),
23+
(state) => selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }),
2524
);
2625
const isLibrary = useSelector(selectors.app.isLibrary) as boolean;
26+
const isCreateBlock = useSelector(selectors.app.isCreateBlock) as boolean;
2727
const {
2828
error,
2929
validateEntry,
@@ -37,7 +37,7 @@ const VideoEditor: React.FC<EditorComponent> = ({
3737
returnFunction={returnFunction}
3838
validateEntry={validateEntry}
3939
>
40-
{studioViewFinished ? (
40+
{(isCreateBlock || studioViewFinished) ? (
4141
<div className="video-editor">
4242
<VideoEditorModal {...{ isLibrary }} />
4343
</div>

src/editors/data/redux/app/selectors.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ describe('app selectors unit tests', () => {
9898
};
9999

100100
[
101-
[[null, truthy.blockValue, true] as [any, any, any], true] as const,
102-
[[null, null, true] as [any, any, any], false] as const,
101+
[[null, truthy.blockValue, true, false] as [any, any, any, any], true] as const,
102+
[[null, null, true, false] as [any, any, any, any], false] as const,
103103
].map(([args, expected]) => expect(cb(...args)).toEqual(expected));
104104
});
105105
});
@@ -112,9 +112,9 @@ describe('app selectors unit tests', () => {
112112
};
113113

114114
[
115-
[[null, truthy.blockValue, false] as [any, any, any], false] as const,
116-
[[truthy.unitUrl, null, false] as [any, any, any], false] as const,
117-
[[truthy.unitUrl, truthy.blockValue, false] as [any, any, any], true] as const,
115+
[[null, truthy.blockValue, false, false] as [any, any, any, any], false] as const,
116+
[[truthy.unitUrl, null, false, false] as [any, any, any, any], false] as const,
117+
[[truthy.unitUrl, truthy.blockValue, false, false] as [any, any, any, any], true] as const,
118118
].map(([args, expected]) => expect(cb(...args)).toEqual(expected));
119119
});
120120
});

src/editors/data/redux/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ import { AdvancedProblemType, ProblemType } from '../constants/problem';
1212

1313
export { default as thunkActions } from './thunkActions';
1414

15-
const rootReducer = combineReducers({
15+
const editorReducer = combineReducers({
1616
app: app.reducer,
1717
requests: requests.reducer,
1818
video: video.reducer,
1919
problem: problem.reducer,
2020
game: game.reducer,
2121
});
2222

23+
const rootReducer = (state: any, action: any) => {
24+
if (action.type === 'resetEditor') {
25+
return editorReducer(undefined, action);
26+
}
27+
28+
return editorReducer(state, action);
29+
};
30+
2331
const actions = StrictDict({
2432
app: app.actions,
2533
requests: requests.actions,

src/editors/data/redux/thunkActions/problem.ts

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export const getDataFromOlx = ({ rawOLX, rawSettings, defaultSettings }) => {
5959
};
6060

6161
export const loadProblem = ({ rawOLX, rawSettings, defaultSettings }) => (dispatch) => {
62-
console.debug(rawOLX);
6362
if (isBlankProblem({ rawOLX })) {
6463
dispatch(actions.problem.setEnableTypeSelection(camelizeKeys(defaultSettings)));
6564
} else {

src/editors/data/redux/thunkActions/requests.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { v4 as uuid4 } from 'uuid';
12
import { StrictDict, parseLibraryImageData, getLibraryImageAssets } from '../../../utils';
23

34
import { RequestKeys } from '../../constants/requests';
45
import api, { loadImages } from '../../services/cms/api';
56
import { actions as requestsActions } from '../requests';
67
import { selectors as appSelectors } from '../app';
7-
import { v4 as uuid4 } from 'uuid';
8-
98

109
// This 'module' self-import hack enables mocking during tests.
1110
// See src/editors/decisions/0005-internal-editor-testability-decisions.md. The whole approach to how hooks are tested

src/editors/hooks.ts

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export const createBlock = ({
7171
destination,
7272
dispatch,
7373
returnFunction,
74-
validateEntry,
7574
}) => {
7675
if (!content) {
7776
return;

0 commit comments

Comments
 (0)