From 8c298336fca485c5fa56b34023574c17192abf93 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Tue, 1 Nov 2022 22:25:12 +0100 Subject: [PATCH] fix: hide canvas-modifying UI in view mode (#5815) * fix: hide canvas-modifying UI in view mode * add class for better targeting * fix missing `key` * fix: useOutsideClick not working in view mode --- src/components/LayerUI.tsx | 30 +++++++++++++++++----------- src/components/MobileMenu.tsx | 34 ++++++++++++++++++-------------- src/components/WelcomeScreen.tsx | 32 +++++++++++++++++++----------- src/hooks/useOutsideClick.ts | 5 +++-- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx index a447ed2a..2cf20d01 100644 --- a/src/components/LayerUI.tsx +++ b/src/components/LayerUI.tsx @@ -213,7 +213,8 @@ const LayerUI = ({ padding={2} style={{ zIndex: 1 }} > - {actionManager.renderAction("loadScene")} + {!appState.viewModeEnabled && + actionManager.renderAction("loadScene")} {/* // TODO barnabasmolnar/editor-redesign */} {/* is this fine here? */} {appState.fileHandle && @@ -234,7 +235,8 @@ const LayerUI = ({ /> )} {actionManager.renderAction("toggleShortcuts", undefined, true)} - {actionManager.renderAction("clearCanvas")} + {!appState.viewModeEnabled && + actionManager.renderAction("clearCanvas")} @@ -249,14 +251,16 @@ const LayerUI = ({
-
-
- {t("labels.canvasBackground")} + {!appState.viewModeEnabled && ( +
+
+ {t("labels.canvasBackground")} +
+
+ {actionManager.renderAction("changeViewBackgroundColor")} +
-
- {actionManager.renderAction("changeViewBackgroundColor")} -
-
+ )}
@@ -299,12 +303,12 @@ const LayerUI = ({ return ( {renderWelcomeScreen && !appState.isLoading && ( - + )}
@@ -405,7 +409,9 @@ const LayerUI = ({ /> )} {renderTopRightUI?.(device.isMobile, appState)} - + {!appState.viewModeEnabled && ( + + )}
diff --git a/src/components/MobileMenu.tsx b/src/components/MobileMenu.tsx index 732d8fce..59dd299d 100644 --- a/src/components/MobileMenu.tsx +++ b/src/components/MobileMenu.tsx @@ -75,7 +75,7 @@ export const MobileMenu = ({ return ( {renderWelcomeScreen && !appState.isLoading && ( - + )}
{(heading: React.ReactNode) => ( @@ -127,11 +127,13 @@ export const MobileMenu = ({ title={t("toolBar.lock")} isMobile /> - + {!appState.viewModeEnabled && ( + + )} @@ -187,7 +189,7 @@ export const MobileMenu = ({ } return ( <> - {actionManager.renderAction("loadScene")} + {!appState.viewModeEnabled && actionManager.renderAction("loadScene")} {renderJSONExportDialog()} {renderImageExportDialog()} )} {actionManager.renderAction("toggleShortcuts", undefined, true)} - {actionManager.renderAction("clearCanvas")} + {!appState.viewModeEnabled && actionManager.renderAction("clearCanvas")} -
-
- {t("labels.canvasBackground")} + {!appState.viewModeEnabled && ( +
+
+ {t("labels.canvasBackground")} +
+
+ {actionManager.renderAction("changeViewBackgroundColor")} +
-
- {actionManager.renderAction("changeViewBackgroundColor")} -
-
+ )} {actionManager.renderAction("toggleTheme")} ); diff --git a/src/components/WelcomeScreen.tsx b/src/components/WelcomeScreen.tsx index 03eb0585..6649346d 100644 --- a/src/components/WelcomeScreen.tsx +++ b/src/components/WelcomeScreen.tsx @@ -5,6 +5,7 @@ import { getShortcutFromShortcutName } from "../actions/shortcuts"; import { COOKIES } from "../constants"; import { collabDialogShownAtom } from "../excalidraw-app/collab/Collab"; import { t } from "../i18n"; +import { AppState } from "../types"; import { ExcalLogo, HelpIcon, @@ -60,7 +61,13 @@ const WelcomeScreenItem = ({ ); }; -const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => { +const WelcomeScreen = ({ + appState, + actionManager, +}: { + appState: AppState; + actionManager: ActionManager; +}) => { const [, setCollabDialogShown] = useAtom(collabDialogShownAtom); let subheadingJSX; @@ -68,12 +75,13 @@ const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => { if (isExcalidrawPlusSignedUser) { subheadingJSX = t("welcomeScreen.switchToPlusApp") .split(/(Excalidraw\+)/) - .map((bit) => { + .map((bit, idx) => { if (bit === "Excalidraw+") { return ( Excalidraw+ @@ -94,15 +102,17 @@ const WelcomeScreen = ({ actionManager }: { actionManager: ActionManager }) => { {subheadingJSX}
- actionManager.executeAction(actionLoadScene)} - shortcut={getShortcutFromShortcutName("loadScene")} - icon={LoadIcon} - /> + {!appState.viewModeEnabled && ( + actionManager.executeAction(actionLoadScene)} + shortcut={getShortcutFromShortcutName("loadScene")} + icon={LoadIcon} + /> + )} void) => { handler(event); }; - document.addEventListener("mousedown", listener); + + document.addEventListener("pointerdown", listener); document.addEventListener("touchstart", listener); return () => { - document.removeEventListener("mousedown", listener); + document.removeEventListener("pointerdown", listener); document.removeEventListener("touchstart", listener); }; },