From df14c69977c56e3c85324a61af6235bcd35b7fd8 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 14 Jul 2022 16:13:10 +0530 Subject: [PATCH] refactor: don't pass zenModeEnable, viewModeEnabled and toggleZenMode props to LayerUI (#5444) refactor: don't pass zenModeEnabled and viewModeEnabled props to LayerUI --- src/components/App.tsx | 12 ++------- src/components/LayerUI.tsx | 51 +++++++++++++++++------------------ src/components/MobileMenu.tsx | 10 +++---- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 7f7efa39..363091ef 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -469,7 +469,6 @@ class App extends React.Component { } public render() { - const { zenModeEnabled, viewModeEnabled } = this.state; const selectedElement = getSelectedElements( this.scene.getNonDeletedElements(), this.state, @@ -484,7 +483,7 @@ class App extends React.Component { return (
{ files: null, }) } - zenModeEnabled={zenModeEnabled} - toggleZenMode={this.toggleZenMode} langCode={getLanguage().code} isCollaborating={this.props.isCollaborating} renderTopRightUI={renderTopRightUI} renderCustomFooter={renderFooter} renderCustomStats={renderCustomStats} - viewModeEnabled={viewModeEnabled} showExitZenModeBtn={ typeof this.props?.zenModeEnabled === "undefined" && - zenModeEnabled + this.state.zenModeEnabled } showThemeBtn={ typeof this.props?.theme === "undefined" && @@ -1632,10 +1628,6 @@ class App extends React.Component { }); }; - toggleZenMode = () => { - this.actionManager.executeAction(actionToggleZenMode); - }; - scrollToContent = ( target: | ExcalidrawElement diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx index 72a6b0e1..263abd5f 100644 --- a/src/components/LayerUI.tsx +++ b/src/components/LayerUI.tsx @@ -39,6 +39,7 @@ import { trackEvent } from "../analytics"; import { useDevice } from "../components/App"; import { Stats } from "./Stats"; import { actionToggleStats } from "../actions/actionToggleStats"; +import { actionToggleZenMode } from "../actions"; interface LayerUIProps { actionManager: ActionManager; @@ -51,16 +52,13 @@ interface LayerUIProps { onLockToggle: () => void; onPenModeToggle: () => void; onInsertElements: (elements: readonly NonDeletedExcalidrawElement[]) => void; - zenModeEnabled: boolean; showExitZenModeBtn: boolean; showThemeBtn: boolean; - toggleZenMode: () => void; langCode: Language["code"]; isCollaborating: boolean; renderTopRightUI?: ExcalidrawProps["renderTopRightUI"]; renderCustomFooter?: ExcalidrawProps["renderFooter"]; renderCustomStats?: ExcalidrawProps["renderCustomStats"]; - viewModeEnabled: boolean; libraryReturnUrl: ExcalidrawProps["libraryReturnUrl"]; UIOptions: AppProps["UIOptions"]; focusContainer: () => void; @@ -79,15 +77,12 @@ const LayerUI = ({ onLockToggle, onPenModeToggle, onInsertElements, - zenModeEnabled, showExitZenModeBtn, showThemeBtn, - toggleZenMode, isCollaborating, renderTopRightUI, renderCustomFooter, renderCustomStats, - viewModeEnabled, libraryReturnUrl, UIOptions, focusContainer, @@ -171,7 +166,7 @@ const LayerUI = ({
{/* the zIndex ensures this menu has higher stacking order, @@ -192,7 +187,7 @@ const LayerUI = ({
{/* the zIndex ensures this menu has higher stacking order, @@ -232,7 +227,7 @@ const LayerUI = ({
- {viewModeEnabled + {appState.viewModeEnabled ? renderViewModeCanvasActions() : renderCanvasActions()} {shouldRenderSelectedShapeActions && renderSelectedShapeActions()} - {!viewModeEnabled && ( + {!appState.viewModeEnabled && (
{(heading) => ( onLockToggle()} title={t("toolBar.lock")} @@ -335,7 +332,7 @@ const LayerUI = ({ @@ -396,7 +393,8 @@ const LayerUI = ({ className={clsx( "layer-ui__wrapper__footer-left zen-mode-transition", { - "layer-ui__wrapper__footer-left--transition-left": zenModeEnabled, + "layer-ui__wrapper__footer-left--transition-left": + appState.zenModeEnabled, }, )} > @@ -408,12 +406,12 @@ const LayerUI = ({ zoom={appState.zoom} /> - {!viewModeEnabled && ( + {!appState.viewModeEnabled && ( <>
{actionManager.renderAction("undo", { size: "small" })} @@ -423,20 +421,20 @@ const LayerUI = ({
{actionManager.renderAction("eraser", { size: "small" })}
)} - {!viewModeEnabled && + {!appState.viewModeEnabled && appState.multiElement && device.isTouchScreen && (
{actionManager.renderAction("finalize", { size: "small" })} @@ -450,7 +448,7 @@ const LayerUI = ({ "layer-ui__wrapper__footer-center zen-mode-transition", { "layer-ui__wrapper__footer-left--transition-bottom": - zenModeEnabled, + appState.zenModeEnabled, }, )} > @@ -460,7 +458,7 @@ const LayerUI = ({ className={clsx( "layer-ui__wrapper__footer-right zen-mode-transition", { - "transition-right disable-pointerEvents": zenModeEnabled, + "transition-right disable-pointerEvents": appState.zenModeEnabled, }, )} > @@ -470,7 +468,7 @@ const LayerUI = ({ className={clsx("disable-zen-mode", { "disable-zen-mode--visible": showExitZenModeBtn, })} - onClick={toggleZenMode} + onClick={() => actionManager.executeAction(actionToggleZenMode)} > {t("buttons.exitZenMode")} @@ -543,7 +541,6 @@ const LayerUI = ({ canvas={canvas} isCollaborating={isCollaborating} renderCustomFooter={renderCustomFooter} - viewModeEnabled={viewModeEnabled} showThemeBtn={showThemeBtn} onImageAction={onImageAction} renderTopRightUI={renderTopRightUI} diff --git a/src/components/MobileMenu.tsx b/src/components/MobileMenu.tsx index ea45b393..3e68110f 100644 --- a/src/components/MobileMenu.tsx +++ b/src/components/MobileMenu.tsx @@ -36,7 +36,6 @@ type MobileMenuProps = { isMobile: boolean, appState: AppState, ) => JSX.Element | null; - viewModeEnabled: boolean; showThemeBtn: boolean; onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void; renderTopRightUI?: ( @@ -60,7 +59,6 @@ export const MobileMenu = ({ canvas, isCollaborating, renderCustomFooter, - viewModeEnabled, showThemeBtn, onImageAction, renderTopRightUI, @@ -125,7 +123,7 @@ export const MobileMenu = ({ !appState.editingElement && getSelectedElements(elements, appState).length === 0; - if (viewModeEnabled) { + if (appState.viewModeEnabled) { return (
{actionManager.renderAction("toggleCanvasMenu")} @@ -151,7 +149,7 @@ export const MobileMenu = ({ }; const renderCanvasActions = () => { - if (viewModeEnabled) { + if (appState.viewModeEnabled) { return ( <> {renderJSONExportDialog()} @@ -185,7 +183,7 @@ export const MobileMenu = ({ }; return ( <> - {!viewModeEnabled && renderToolbar()} + {!appState.viewModeEnabled && renderToolbar()} {renderStats()}
) : appState.openMenu === "shape" && - !viewModeEnabled && + !appState.viewModeEnabled && showSelectedShapeActions(appState, elements) ? (