Skip to content

Commit 8f9e7a6

Browse files
committed
Got rid of last bit of blocksEditor
1 parent a2e0a10 commit 8f9e7a6

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ const App: React.FC = () => {
205205
array.sort();
206206
storage.saveEntry('shownPythonToolboxCategories', JSON.stringify(array));
207207
};
208+
const areBlocksModified = () : boolean => {
209+
if(blocksEditor.current){
210+
return blocksEditor.current.isModified();
211+
}
212+
return false;
213+
}
208214

209215
return (
210216
<Antd.ConfigProvider
@@ -244,7 +250,7 @@ const App: React.FC = () => {
244250
messageApi={messageApi}
245251
setAlertErrorMessage={setAlertErrorMessage}
246252
saveBlocks={saveBlocks}
247-
blocksEditor={blocksEditor.current}
253+
areBlocksModified={areBlocksModified}
248254
initializeShownPythonToolboxCategories={initializeShownPythonToolboxCategories}
249255
currentModule={currentModule}
250256
setCurrentModule={setCurrentModule}

src/reactComponents/ModuleOutline.tsx

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import * as commonStorage from '../storage/common_storage';
2525
import * as I18Next from "react-i18next";
2626
import * as NewProjectNameModal from './NewProjectNameModal';
2727
import * as NewModuleNameModal from './NewModuleNameModal';
28-
import * as editor from '../editor/editor';
2928
import type { MessageInstance } from 'antd/es/message/interface';
3029

3130
import {
@@ -39,10 +38,10 @@ interface ModuleOutlineProps {
3938
initializeShownPythonToolboxCategories: () => void;
4039
storage: commonStorage.Storage | null;
4140
messageApi: MessageInstance;
42-
blocksEditor: editor.Editor | null;
4341
currentModule: commonStorage.Module | null;
4442
setCurrentModule: (module: commonStorage.Module | null) => void;
4543
saveBlocks: () => Promise<boolean>;
44+
areBlocksModified: () => boolean;
4645
}
4746

4847
export default function ModuleOutline(props: ModuleOutlineProps) {
@@ -259,32 +258,30 @@ export default function ModuleOutline(props: ModuleOutlineProps) {
259258
};
260259

261260
const checkIfBlocksWereModified = (callback: () => void) => {
262-
if (props.blocksEditor) {
263-
if (!currentModulePath) {
261+
if (!currentModulePath) {
262+
callback();
263+
return;
264+
}
265+
if (!props.areBlocksModified()) {
266+
callback();
267+
return;
268+
}
269+
270+
// Show a bubble confirmation box to ask the user if they want to save the blocks.
271+
setPopconfirmTitle('Blocks have been modified!');
272+
setPopconfirmDescription('Press ok to save and continue');
273+
// Set the function to be executed if the user clicks 'ok'.
274+
afterPopconfirmOk.current = async () => {
275+
setPopconfirmLoading(true);
276+
const success = await props.saveBlocks();
277+
setOpenPopconfirm(false);
278+
setPopconfirmLoading(false);
279+
if (success) {
264280
callback();
265-
return;
266281
}
267-
if (!props.blocksEditor.isModified()) {
268-
callback();
269-
return;
270-
}
271-
272-
// Show a bubble confirmation box to ask the user if they want to save the blocks.
273-
setPopconfirmTitle('Blocks have been modified!');
274-
setPopconfirmDescription('Press ok to save and continue');
275-
// Set the function to be executed if the user clicks 'ok'.
276-
afterPopconfirmOk.current = async () => {
277-
setPopconfirmLoading(true);
278-
const success = await props.saveBlocks();
279-
setOpenPopconfirm(false);
280-
setPopconfirmLoading(false);
281-
if (success) {
282-
callback();
283-
}
284-
};
285-
setOpenPopconfirm(true);
286-
}
287-
};
282+
};
283+
setOpenPopconfirm(true);
284+
}
288285

289286
const handleNewModuleNameOk = async (newModuleClassName: string) => {
290287
if (!props.storage || !props.currentModule) {

0 commit comments

Comments
 (0)