2021-10-14 22:56:51 +05:30
|
|
|
import { useEffect, useState } from "react";
|
2023-09-21 09:28:48 +05:30
|
|
|
import { debounce, getVersion, nFormatter } from "../src/utils";
|
2021-03-29 20:06:34 +05:30
|
|
|
import {
|
|
|
|
getElementsStorageSize,
|
|
|
|
getTotalStorageSize,
|
|
|
|
} from "./data/localStorage";
|
2023-09-21 09:28:48 +05:30
|
|
|
import { DEFAULT_VERSION } from "../src/constants";
|
|
|
|
import { t } from "../src/i18n";
|
|
|
|
import { copyTextToSystemClipboard } from "../src/clipboard";
|
|
|
|
import { NonDeletedExcalidrawElement } from "../src/element/types";
|
|
|
|
import { UIAppState } from "../src/types";
|
2023-05-08 10:14:02 +02:00
|
|
|
|
2021-03-29 20:06:34 +05:30
|
|
|
type StorageSizes = { scene: number; total: number };
|
|
|
|
|
|
|
|
const STORAGE_SIZE_TIMEOUT = 500;
|
|
|
|
|
|
|
|
const getStorageSizes = debounce((cb: (sizes: StorageSizes) => void) => {
|
|
|
|
cb({
|
|
|
|
scene: getElementsStorageSize(),
|
|
|
|
total: getTotalStorageSize(),
|
|
|
|
});
|
|
|
|
}, STORAGE_SIZE_TIMEOUT);
|
|
|
|
|
|
|
|
type Props = {
|
2022-07-11 18:11:13 +05:30
|
|
|
setToast: (message: string) => void;
|
2022-08-22 17:18:25 +05:30
|
|
|
elements: readonly NonDeletedExcalidrawElement[];
|
2023-05-08 10:14:02 +02:00
|
|
|
appState: UIAppState;
|
2021-03-29 20:06:34 +05:30
|
|
|
};
|
|
|
|
const CustomStats = (props: Props) => {
|
|
|
|
const [storageSizes, setStorageSizes] = useState<StorageSizes>({
|
|
|
|
scene: 0,
|
|
|
|
total: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
getStorageSizes((sizes) => {
|
|
|
|
setStorageSizes(sizes);
|
|
|
|
});
|
2022-08-22 17:18:25 +05:30
|
|
|
}, [props.elements, props.appState]);
|
2021-03-29 20:06:34 +05:30
|
|
|
useEffect(() => () => getStorageSizes.cancel(), []);
|
|
|
|
|
|
|
|
const version = getVersion();
|
|
|
|
let hash;
|
|
|
|
let timestamp;
|
|
|
|
|
|
|
|
if (version !== DEFAULT_VERSION) {
|
|
|
|
timestamp = version.slice(0, 16).replace("T", " ");
|
|
|
|
hash = version.slice(21);
|
|
|
|
} else {
|
|
|
|
timestamp = t("stats.versionNotAvailable");
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<tr>
|
|
|
|
<th colSpan={2}>{t("stats.storage")}</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>{t("stats.scene")}</td>
|
|
|
|
<td>{nFormatter(storageSizes.scene, 1)}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>{t("stats.total")}</td>
|
|
|
|
<td>{nFormatter(storageSizes.total, 1)}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th colSpan={2}>{t("stats.version")}</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td
|
|
|
|
colSpan={2}
|
|
|
|
style={{ textAlign: "center", cursor: "pointer" }}
|
|
|
|
onClick={async () => {
|
|
|
|
try {
|
|
|
|
await copyTextToSystemClipboard(getVersion());
|
2022-07-11 18:11:13 +05:30
|
|
|
props.setToast(t("toast.copyToClipboard"));
|
2021-03-29 20:06:34 +05:30
|
|
|
} catch {}
|
|
|
|
}}
|
|
|
|
title={t("stats.versionCopy")}
|
|
|
|
>
|
|
|
|
{timestamp}
|
|
|
|
<br />
|
|
|
|
{hash}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CustomStats;
|