add toast message when reconnecting to server
This commit is contained in:
parent
f8c9f63650
commit
c71495b140
@ -8,6 +8,7 @@ export const SYNC_BROWSER_TABS_TIMEOUT = 50;
|
|||||||
export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
|
export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
|
||||||
export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
|
export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
|
||||||
export const HIDDEN_DISCONNECT_TIMEOUT = 30000;
|
export const HIDDEN_DISCONNECT_TIMEOUT = 30000;
|
||||||
|
export const RECONNECT_TOAST_DURATION = 2000;
|
||||||
|
|
||||||
export const FILE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024; // 3 MiB
|
export const FILE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024; // 3 MiB
|
||||||
// 1 year (https://stackoverflow.com/a/25201898/927631)
|
// 1 year (https://stackoverflow.com/a/25201898/927631)
|
||||||
|
@ -44,6 +44,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
FIREBASE_STORAGE_PREFIXES,
|
FIREBASE_STORAGE_PREFIXES,
|
||||||
HIDDEN_DISCONNECT_TIMEOUT,
|
HIDDEN_DISCONNECT_TIMEOUT,
|
||||||
|
RECONNECT_TOAST_DURATION,
|
||||||
STORAGE_KEYS,
|
STORAGE_KEYS,
|
||||||
SYNC_BROWSER_TABS_TIMEOUT,
|
SYNC_BROWSER_TABS_TIMEOUT,
|
||||||
} from "./app_constants";
|
} from "./app_constants";
|
||||||
@ -84,6 +85,7 @@ import { Provider, useAtom } from "jotai";
|
|||||||
import { jotaiStore, useAtomWithInitialValue } from "../jotai";
|
import { jotaiStore, useAtomWithInitialValue } from "../jotai";
|
||||||
import { reconcileElements } from "./collab/reconciliation";
|
import { reconcileElements } from "./collab/reconciliation";
|
||||||
import { parseLibraryTokensFromUrl, useHandleLibrary } from "../data/library";
|
import { parseLibraryTokensFromUrl, useHandleLibrary } from "../data/library";
|
||||||
|
import { Toast } from "../components/Toast";
|
||||||
|
|
||||||
polyfill();
|
polyfill();
|
||||||
window.EXCALIDRAW_THROTTLE_RENDER = true;
|
window.EXCALIDRAW_THROTTLE_RENDER = true;
|
||||||
@ -250,6 +252,8 @@ const PlusAppLinkJSX = (
|
|||||||
|
|
||||||
const ExcalidrawWrapper = () => {
|
const ExcalidrawWrapper = () => {
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
const [toast, setToast] = useState<AppState["toast"]>(null);
|
||||||
|
const disconnectRef = useRef(false);
|
||||||
let currentLangCode = languageDetector.detect() || defaultLang.code;
|
let currentLangCode = languageDetector.detect() || defaultLang.code;
|
||||||
if (Array.isArray(currentLangCode)) {
|
if (Array.isArray(currentLangCode)) {
|
||||||
currentLangCode = currentLangCode[0];
|
currentLangCode = currentLangCode[0];
|
||||||
@ -470,6 +474,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
() => collabAPI.stopCollaboration(false),
|
() => collabAPI.stopCollaboration(false),
|
||||||
HIDDEN_DISCONNECT_TIMEOUT,
|
HIDDEN_DISCONNECT_TIMEOUT,
|
||||||
);
|
);
|
||||||
|
disconnectRef.current = true;
|
||||||
};
|
};
|
||||||
const cancelPrevDisconnect = () => clearTimeout(disconnectTimeout);
|
const cancelPrevDisconnect = () => clearTimeout(disconnectTimeout);
|
||||||
|
|
||||||
@ -479,14 +484,26 @@ const ExcalidrawWrapper = () => {
|
|||||||
} else {
|
} else {
|
||||||
cancelPrevDisconnect();
|
cancelPrevDisconnect();
|
||||||
disconnect();
|
disconnect();
|
||||||
|
setToast(null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cancelPrevDisconnect();
|
cancelPrevDisconnect();
|
||||||
if (!collabAPI.isCollaborating()) {
|
if (!collabAPI.isCollaborating()) {
|
||||||
initializeScene({ collabAPI, excalidrawAPI }).then(async (data) => {
|
if (!toast && disconnectRef.current) {
|
||||||
loadImages(data, /* isInitialLoad */ true);
|
setToast({
|
||||||
initialStatePromiseRef.current.promise.resolve(data.scene);
|
message: t("toast.reconnectRoomServer"),
|
||||||
});
|
duration: RECONNECT_TOAST_DURATION,
|
||||||
|
closable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
disconnectRef.current &&
|
||||||
|
initializeScene({ collabAPI, excalidrawAPI }).then(
|
||||||
|
async (data) => {
|
||||||
|
loadImages(data, /* isInitialLoad */ true);
|
||||||
|
initialStatePromiseRef.current.promise.resolve(data.scene);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
disconnectRef.current = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,7 +526,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
);
|
);
|
||||||
clearTimeout(titleTimeout);
|
clearTimeout(titleTimeout);
|
||||||
};
|
};
|
||||||
}, [collabAPI, excalidrawAPI]);
|
}, [collabAPI, excalidrawAPI, toast]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unloadHandler = (event: BeforeUnloadEvent) => {
|
const unloadHandler = (event: BeforeUnloadEvent) => {
|
||||||
@ -719,7 +736,7 @@ const ExcalidrawWrapper = () => {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{ height: "100%" }}
|
style={{ height: "100%" }}
|
||||||
className={clsx("excalidraw-app", {
|
className={clsx("excalidraw excalidraw-app", {
|
||||||
"is-collaborating": isCollaborating,
|
"is-collaborating": isCollaborating,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
@ -769,6 +786,14 @@ const ExcalidrawWrapper = () => {
|
|||||||
onClose={() => setErrorMessage("")}
|
onClose={() => setErrorMessage("")}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{toast && (
|
||||||
|
<Toast
|
||||||
|
message={toast.message}
|
||||||
|
duration={toast.duration}
|
||||||
|
closable={toast.closable}
|
||||||
|
onClose={() => setToast(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -387,7 +387,8 @@
|
|||||||
"fileSaved": "File saved.",
|
"fileSaved": "File saved.",
|
||||||
"fileSavedToFilename": "Saved to {filename}",
|
"fileSavedToFilename": "Saved to {filename}",
|
||||||
"canvas": "canvas",
|
"canvas": "canvas",
|
||||||
"selection": "selection"
|
"selection": "selection",
|
||||||
|
"reconnectRoomServer": "Reconnecting to server"
|
||||||
},
|
},
|
||||||
"colors": {
|
"colors": {
|
||||||
"ffffff": "White",
|
"ffffff": "White",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user