mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Store username for every room (#1381)
* store username for every room * add missing fun
This commit is contained in:
parent
5e2f164026
commit
7b3816d0d3
4 changed files with 56 additions and 7 deletions
|
@ -5,6 +5,33 @@ import { restore } from "./restore";
|
|||
|
||||
const LOCAL_STORAGE_KEY = "excalidraw";
|
||||
const LOCAL_STORAGE_KEY_STATE = "excalidraw-state";
|
||||
const LOCAL_STORAGE_KEY_COLLAB = "excalidraw-collab";
|
||||
|
||||
export function saveUsernameToLocalStorage(id: string, username: string) {
|
||||
try {
|
||||
localStorage.setItem(
|
||||
`${LOCAL_STORAGE_KEY_COLLAB}-${id}`,
|
||||
JSON.stringify({ username }),
|
||||
);
|
||||
} catch (error) {
|
||||
// Unable to access window.localStorage
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export function restoreUsernameFromLocalStorage(id: string): string | null {
|
||||
try {
|
||||
const data = localStorage.getItem(`${LOCAL_STORAGE_KEY_COLLAB}-${id}`);
|
||||
if (data) {
|
||||
return JSON.parse(data).username;
|
||||
}
|
||||
} catch (error) {
|
||||
// Unable to access localStorage
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function saveToLocalStorage(
|
||||
elements: readonly ExcalidrawElement[],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue