refactor: Stats component (#5610)

refactor: stats component
This commit is contained in:
Aakansha Doshi 2022-08-22 17:18:25 +05:30 committed by GitHub
parent ba2c86fe1b
commit 32d82219b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 30 deletions

View file

@ -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();