feat: show network stats for collaboration
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// @ts-nocheck
|
||||
import { Point, simplify } from "points-on-curve";
|
||||
import React from "react";
|
||||
import { RoughCanvas } from "roughjs/bin/canvas";
|
||||
@@ -182,6 +183,7 @@ import LayerUI from "./LayerUI";
|
||||
import { Stats } from "./Stats";
|
||||
import { Toast } from "./Toast";
|
||||
import { actionToggleViewMode } from "../actions/actionToggleViewMode";
|
||||
import { getNetworkSpeed } from "../networkStats";
|
||||
|
||||
const { history } = createHistory();
|
||||
|
||||
@@ -461,6 +463,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
setAppState={this.setAppState}
|
||||
elements={this.scene.getElements()}
|
||||
onClose={this.toggleStats}
|
||||
isCollaborating={this.props.isCollaborating}
|
||||
/>
|
||||
)}
|
||||
{this.state.toastMessage !== null && (
|
||||
@@ -845,6 +848,21 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
this.addEventListeners();
|
||||
}
|
||||
|
||||
if (
|
||||
prevState.showStats !== this.state.showStats ||
|
||||
prevProps.isCollaborating !== this.props.isCollaborating
|
||||
) {
|
||||
if (this.state.showStats && this.props.isCollaborating) {
|
||||
this.calculateNetStats();
|
||||
navigator.connection.addEventListener("change", this.calculateNetStats);
|
||||
} else {
|
||||
navigator.connection.removeEventListener(
|
||||
"change",
|
||||
this.calculateNetStats,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
document
|
||||
.querySelector(".excalidraw")
|
||||
?.classList.toggle("Appearance_dark", this.state.appearance === "dark");
|
||||
@@ -970,6 +988,11 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
}
|
||||
}
|
||||
|
||||
private calculateNetStats = async () => {
|
||||
const speed = await getNetworkSpeed();
|
||||
const networkSpeed = speed === -1 ? "Error!" : speed;
|
||||
this.setState({ networkSpeed });
|
||||
};
|
||||
// Copy/paste
|
||||
|
||||
private onCut = withBatchedUpdates((event: ClipboardEvent) => {
|
||||
|
||||
@@ -30,6 +30,7 @@ export const Stats = (props: {
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
elements: readonly NonDeletedExcalidrawElement[];
|
||||
onClose: () => void;
|
||||
isCollaborating: boolean;
|
||||
}) => {
|
||||
const isMobile = useIsMobile();
|
||||
const [storageSizes, setStorageSizes] = useState<StorageSizes>({
|
||||
@@ -192,6 +193,21 @@ export const Stats = (props: {
|
||||
{hash}
|
||||
</td>
|
||||
</tr>
|
||||
{props.isCollaborating ? (
|
||||
<>
|
||||
<tr>
|
||||
<th colSpan={2}>{t("stats.collaboration")}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{t("stats.collaborators")}</td>
|
||||
<td>{props.appState.collaborators.size}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{t("stats.networkSpeed")}</td>
|
||||
<td>{props.appState.networkSpeed}</td>
|
||||
</tr>
|
||||
</>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</Island>
|
||||
|
||||
Reference in New Issue
Block a user