Store username for every room (#1381)

* store username for every room

* add missing fun
This commit is contained in:
Kostas Bariotis 2020-04-11 17:13:10 +01:00 committed by GitHub
parent 5e2f164026
commit 7b3816d0d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 7 deletions

View file

@ -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[],