Global username instead of per room (#1382)
* global username * remove string interpolation Co-Authored-By: Lipis <lipiridis@gmail.com> * remove string interpolation Co-Authored-By: Lipis <lipiridis@gmail.com> * remove backwards compat Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
parent
166ad0412c
commit
2adae4132b
@ -244,9 +244,7 @@ export class App extends React.Component<any, AppState> {
|
||||
onRoomCreate={this.openPortal}
|
||||
onRoomDestroy={this.closePortal}
|
||||
onUsernameChange={(username) => {
|
||||
if (this.portal.socket && this.portal.roomID && username) {
|
||||
saveUsernameToLocalStorage(this.portal.roomID, username);
|
||||
}
|
||||
saveUsernameToLocalStorage(username);
|
||||
this.setState({
|
||||
username,
|
||||
});
|
||||
@ -921,12 +919,12 @@ export class App extends React.Component<any, AppState> {
|
||||
);
|
||||
|
||||
this.portal.socket!.on("init-room", () => {
|
||||
if (this.portal.socket && this.portal.roomID) {
|
||||
const username = restoreUsernameFromLocalStorage(this.portal.roomID);
|
||||
if (this.portal.socket) {
|
||||
const username = restoreUsernameFromLocalStorage();
|
||||
|
||||
this.portal.socket.emit("join-room", this.portal.roomID);
|
||||
|
||||
if (username) {
|
||||
if (username !== null) {
|
||||
this.setState({
|
||||
username,
|
||||
});
|
||||
|
@ -7,10 +7,10 @@ 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) {
|
||||
export function saveUsernameToLocalStorage(username: string) {
|
||||
try {
|
||||
localStorage.setItem(
|
||||
`${LOCAL_STORAGE_KEY_COLLAB}-${id}`,
|
||||
LOCAL_STORAGE_KEY_COLLAB,
|
||||
JSON.stringify({ username }),
|
||||
);
|
||||
} catch (error) {
|
||||
@ -19,9 +19,9 @@ export function saveUsernameToLocalStorage(id: string, username: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function restoreUsernameFromLocalStorage(id: string): string | null {
|
||||
export function restoreUsernameFromLocalStorage(): string | null {
|
||||
try {
|
||||
const data = localStorage.getItem(`${LOCAL_STORAGE_KEY_COLLAB}-${id}`);
|
||||
const data = localStorage.getItem(LOCAL_STORAGE_KEY_COLLAB);
|
||||
if (data) {
|
||||
return JSON.parse(data).username;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user