Virtual whiteboard for sketching hand-drawn like diagrams
refactor: Stats component (#5610)
Aakansha Doshi32d82219b1d9
diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsxindex a4b28733f9..2d871508a6 100644--- a/src/components/LayerUI.tsx+++ b/src/components/LayerUI.tsx@@ -412,23 +412,6 @@ const LayerUI = ({</>);- const renderStats = () => {- if (!appState.showStats) {- return null;- }- return (- <Stats- appState={appState}- setAppState={setAppState}- elements={elements}- onClose={() => {- actionManager.executeAction(actionToggleStats);- }}- renderCustomStats={renderCustomStats}- />- );- };-return device.isMobile ? (<>{dialogs}@@ -449,7 +432,7 @@ const LayerUI = ({showThemeBtn={showThemeBtn}onImageAction={onImageAction}renderTopRightUI={renderTopRightUI}- renderStats={renderStats}+ renderCustomStats={renderCustomStats}/></>) : (@@ -478,7 +461,17 @@ const LayerUI = ({renderCustomFooter={renderCustomFooter}showExitZenModeBtn={showExitZenModeBtn}/>- {renderStats()}+ {appState.showStats && (+ <Stats+ appState={appState}+ setAppState={setAppState}+ elements={elements}+ onClose={() => {+ actionManager.executeAction(actionToggleStats);+ }}+ renderCustomStats={renderCustomStats}+ />+ )}{appState.scrolledOutside && (<buttonclassName="scroll-back-to-content"diff --git a/src/components/MobileMenu.tsx b/src/components/MobileMenu.tsxindex a8a302823d..f6e28f441b 100644--- a/src/components/MobileMenu.tsx+++ b/src/components/MobileMenu.tsx@@ -1,5 +1,5 @@import React from "react";-import { AppState } from "../types";+import { AppState, ExcalidrawProps } from "../types";import { ActionManager } from "../actions/manager";import { t } from "../i18n";import Stack from "./Stack";@@ -18,6 +18,8 @@ import { UserList } from "./UserList";import { BackgroundPickerAndDarkModeToggle } from "./BackgroundPickerAndDarkModeToggle";import { LibraryButton } from "./LibraryButton";import { PenModeButton } from "./PenModeButton";+import { Stats } from "./Stats";+import { actionToggleStats } from "../actions";type MobileMenuProps = {appState: AppState;@@ -42,7 +44,7 @@ type MobileMenuProps = {isMobile: boolean,appState: AppState,) => JSX.Element | null;- renderStats: () => JSX.Element | null;+ renderCustomStats?: ExcalidrawProps["renderCustomStats"];};export const MobileMenu = ({@@ -62,7 +64,7 @@ export const MobileMenu = ({showThemeBtn,onImageAction,renderTopRightUI,- renderStats,+ renderCustomStats,}: MobileMenuProps) => {const renderToolbar = () => {return (@@ -184,7 +186,17 @@ export const MobileMenu = ({return (<>{!appState.viewModeEnabled && renderToolbar()}- {renderStats()}+ {!appState.openMenu && appState.showStats && (+ <Stats+ appState={appState}+ setAppState={setAppState}+ elements={elements}+ onClose={() => {+ actionManager.executeAction(actionToggleStats);+ }}+ renderCustomStats={renderCustomStats}+ />+ )}<divclassName="App-bottom-bar"style={{diff --git a/src/components/Stats.tsx b/src/components/Stats.tsxindex b3f2816c9e..dc7c7965ae 100644--- a/src/components/Stats.tsx+++ b/src/components/Stats.tsx@@ -2,7 +2,6 @@ import React from "react";import { getCommonBounds } from "../element/bounds";import { NonDeletedExcalidrawElement } from "../element/types";import { t } from "../i18n";-import { useDevice } from "../components/App";import { getTargetElements } from "../scene";import { AppState, ExcalidrawProps } from "../types";import { close } from "./icons";@@ -16,13 +15,10 @@ export const Stats = (props: {onClose: () => void;renderCustomStats: ExcalidrawProps["renderCustomStats"];}) => {- const device = useDevice();const boundingBox = getCommonBounds(props.elements);const selectedElements = getTargetElements(props.elements, props.appState);const selectedBoundingBox = getCommonBounds(selectedElements);- if (device.isMobile && props.appState.openMenu) {- return null;- }+return (<div className="Stats"><Island padding={2}>diff --git a/src/excalidraw-app/CustomStats.tsx b/src/excalidraw-app/CustomStats.tsxindex a849a28b09..d23e67a9f3 100644--- a/src/excalidraw-app/CustomStats.tsx+++ b/src/excalidraw-app/CustomStats.tsx@@ -7,6 +7,8 @@ import {import { DEFAULT_VERSION } from "../constants";import { t } from "../i18n";import { copyTextToSystemClipboard } from "../clipboard";+import { AppState } from "../types";+import { NonDeletedExcalidrawElement } from "../element/types";type StorageSizes = { scene: number; total: number };const STORAGE_SIZE_TIMEOUT = 500;@@ -20,6 +22,8 @@ const getStorageSizes = debounce((cb: (sizes: StorageSizes) => void) => {type Props = {setToast: (message: string) => void;+ elements: readonly NonDeletedExcalidrawElement[];+ appState: AppState;};const CustomStats = (props: Props) => {const [storageSizes, setStorageSizes] = useState<StorageSizes>({@@ -31,7 +35,7 @@ const CustomStats = (props: Props) => {getStorageSizes((sizes) => {setStorageSizes(sizes);});- });+ }, [props.elements, props.appState]);useEffect(() => () => getStorageSizes.cancel(), []);const version = getVersion();diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsxindex 3f059e6d80..896c96d987 100644--- a/src/excalidraw-app/index.tsx+++ b/src/excalidraw-app/index.tsx@@ -666,10 +666,15 @@ const ExcalidrawWrapper = () => {[langCode],);- const renderCustomStats = () => {+ const renderCustomStats = (+ elements: readonly NonDeletedExcalidrawElement[],+ appState: AppState,+ ) => {return (<CustomStatssetToast={(message) => excalidrawAPI!.setToast({ message })}+ appState={appState}+ elements={elements}/>);};