Skip to content

Commit

Permalink
Revert "chore: show snackbar if strategy changed while running bot (b…
Browse files Browse the repository at this point in the history
  • Loading branch information
vinu-deriv committed Oct 13, 2023
1 parent e85f421 commit 97203da
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 242 deletions.
1 change: 0 additions & 1 deletion packages/bot-web-ui/src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
--zindex-drawer: 5;
--zindex-modal: 6;
--zindex-draggable-modal: 7;
--zindex-snackbar: 8;
}

This file was deleted.

36 changes: 0 additions & 36 deletions packages/bot-web-ui/src/components/bot-snackbar/bot-snackbar.scss

This file was deleted.

57 changes: 0 additions & 57 deletions packages/bot-web-ui/src/components/bot-snackbar/bot-snackbar.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions packages/bot-web-ui/src/components/bot-snackbar/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { useRef, useState } from 'react';
import React from 'react';
import classNames from 'classnames';

import { observer } from '@deriv/stores';

import { useDBotStore } from '../../../stores/useDBotStore';
import BotSnackbar from '../../bot-snackbar';
import LoadModal from '../../load-modal';
import SaveModal from '../dashboard-component/load-bot-preview/save-modal';
import BotBuilderTourHandler from '../dbot-tours/bot-builder-tour';
Expand All @@ -13,11 +12,8 @@ import QuickStrategy from '../quick-strategy';
import WorkspaceWrapper from './workspace-wrapper';

const BotBuilder = observer(() => {
const { dashboard, app, run_panel } = useDBotStore();
const { dashboard, app } = useDBotStore();
const { active_tab, active_tour, is_preview_on_popup } = dashboard;
const { is_running } = run_panel;
const is_blockly_listener_registered = useRef(false);
const [show_snackbar, setShowSnackbar] = useState(false);

const { onMount, onUnmount } = app;
const el_ref = React.useRef<HTMLInputElement | null>(null);
Expand All @@ -27,43 +23,8 @@ const BotBuilder = observer(() => {
return () => onUnmount();
}, []);

const handleBlockChangeOnBotRun = (e: Event) => {
if (e.type !== 'ui') {
setShowSnackbar(true);
removeBlockChangeListener();
}
};

const removeBlockChangeListener = () => {
is_blockly_listener_registered.current = false;
window.Blockly?.derivWorkspace?.removeChangeListener(handleBlockChangeOnBotRun);
};

React.useEffect(() => {
const workspace = window.Blockly?.derivWorkspace;
if (workspace && is_running && !is_blockly_listener_registered.current) {
is_blockly_listener_registered.current = true;
workspace.addChangeListener(handleBlockChangeOnBotRun);
} else {
setShowSnackbar(false);
removeBlockChangeListener();
}

return () => {
if (workspace && is_blockly_listener_registered.current) {
removeBlockChangeListener();
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [is_running]);

return (
<>
<BotSnackbar
is_open={show_snackbar}
message='Changes you make will not affect your running bot.'
handleClose={() => setShowSnackbar(false)}
/>
<div
className={classNames('bot-builder', {
'bot-builder--active': active_tab === 1 && !is_preview_on_popup,
Expand Down

0 comments on commit 97203da

Please sign in to comment.