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}
|
onRoomCreate={this.openPortal}
|
||||||
onRoomDestroy={this.closePortal}
|
onRoomDestroy={this.closePortal}
|
||||||
onUsernameChange={(username) => {
|
onUsernameChange={(username) => {
|
||||||
if (this.portal.socket && this.portal.roomID && username) {
|
saveUsernameToLocalStorage(username);
|
||||||
saveUsernameToLocalStorage(this.portal.roomID, username);
|
|
||||||
}
|
|
||||||
this.setState({
|
this.setState({
|
||||||
username,
|
username,
|
||||||
});
|
});
|
||||||
@ -921,12 +919,12 @@ export class App extends React.Component<any, AppState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.portal.socket!.on("init-room", () => {
|
this.portal.socket!.on("init-room", () => {
|
||||||
if (this.portal.socket && this.portal.roomID) {
|
if (this.portal.socket) {
|
||||||
const username = restoreUsernameFromLocalStorage(this.portal.roomID);
|
const username = restoreUsernameFromLocalStorage();
|
||||||
|
|
||||||
this.portal.socket.emit("join-room", this.portal.roomID);
|
this.portal.socket.emit("join-room", this.portal.roomID);
|
||||||
|
|
||||||
if (username) {
|
if (username !== null) {
|
||||||
this.setState({
|
this.setState({
|
||||||
username,
|
username,
|
||||||
});
|
});
|
||||||
|
@ -7,10 +7,10 @@ const LOCAL_STORAGE_KEY = "excalidraw";
|
|||||||
const LOCAL_STORAGE_KEY_STATE = "excalidraw-state";
|
const LOCAL_STORAGE_KEY_STATE = "excalidraw-state";
|
||||||
const LOCAL_STORAGE_KEY_COLLAB = "excalidraw-collab";
|
const LOCAL_STORAGE_KEY_COLLAB = "excalidraw-collab";
|
||||||
|
|
||||||
export function saveUsernameToLocalStorage(id: string, username: string) {
|
export function saveUsernameToLocalStorage(username: string) {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
`${LOCAL_STORAGE_KEY_COLLAB}-${id}`,
|
LOCAL_STORAGE_KEY_COLLAB,
|
||||||
JSON.stringify({ username }),
|
JSON.stringify({ username }),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} 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 {
|
try {
|
||||||
const data = localStorage.getItem(`${LOCAL_STORAGE_KEY_COLLAB}-${id}`);
|
const data = localStorage.getItem(LOCAL_STORAGE_KEY_COLLAB);
|
||||||
if (data) {
|
if (data) {
|
||||||
return JSON.parse(data).username;
|
return JSON.parse(data).username;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user