Prevent having duplicates in pending room state
This commit is contained in:
parent
118556b542
commit
be22a325f6
1 changed files with 10 additions and 14 deletions
|
@ -69,7 +69,7 @@ interface IState {
|
||||||
contextMenuPosition: PartialDOMRect;
|
contextMenuPosition: PartialDOMRect;
|
||||||
isDarkTheme: boolean;
|
isDarkTheme: boolean;
|
||||||
selectedSpace?: Room;
|
selectedSpace?: Room;
|
||||||
pendingRoomJoin: string[]
|
pendingRoomJoin: Set<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
@replaceableComponent("structures.UserMenu")
|
@replaceableComponent("structures.UserMenu")
|
||||||
|
@ -86,7 +86,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
this.state = {
|
this.state = {
|
||||||
contextMenuPosition: null,
|
contextMenuPosition: null,
|
||||||
isDarkTheme: this.isUserOnDarkTheme(),
|
isDarkTheme: this.isUserOnDarkTheme(),
|
||||||
pendingRoomJoin: [],
|
pendingRoomJoin: new Set<string>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
||||||
|
@ -168,28 +168,24 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private addPendingJoinRoom(roomId) {
|
private addPendingJoinRoom(roomId: string): void {
|
||||||
this.setState({
|
this.setState({
|
||||||
pendingRoomJoin: [
|
pendingRoomJoin: new Set<string>(this.state.pendingRoomJoin)
|
||||||
...this.state.pendingRoomJoin,
|
.add(roomId),
|
||||||
roomId,
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private removePendingJoinRoom(roomId) {
|
private removePendingJoinRoom(roomId: string): void {
|
||||||
const newPendingRoomJoin = this.state.pendingRoomJoin.filter(pendingJoinRoomId => {
|
if (this.state.pendingRoomJoin.has(roomId)) {
|
||||||
return pendingJoinRoomId !== roomId;
|
this.state.pendingRoomJoin.delete(roomId);
|
||||||
});
|
|
||||||
if (newPendingRoomJoin.length !== this.state.pendingRoomJoin.length) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
pendingRoomJoin: newPendingRoomJoin,
|
pendingRoomJoin: new Set<string>(this.state.pendingRoomJoin),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get hasPendingActions(): boolean {
|
get hasPendingActions(): boolean {
|
||||||
return this.state.pendingRoomJoin.length > 0;
|
return Array.from(this.state.pendingRoomJoin).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private onOpenMenuClick = (ev: React.MouseEvent) => {
|
private onOpenMenuClick = (ev: React.MouseEvent) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue