Merge pull request #6108 from matrix-org/gsouquet/fix/17473
This commit is contained in:
commit
fd7bc9755a
2 changed files with 17 additions and 20 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);
|
||||||
|
@ -106,6 +106,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
||||||
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
||||||
this.tagStoreRef = GroupFilterOrderStore.addListener(this.onTagStoreUpdate);
|
this.tagStoreRef = GroupFilterOrderStore.addListener(this.onTagStoreUpdate);
|
||||||
|
MatrixClientPeg.get().on("Room", this.onRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
|
@ -117,6 +118,11 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
if (SettingsStore.getValue("feature_spaces")) {
|
if (SettingsStore.getValue("feature_spaces")) {
|
||||||
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
||||||
}
|
}
|
||||||
|
MatrixClientPeg.get().removeListener("Room", this.onRoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onRoom = (room: Room): void => {
|
||||||
|
this.removePendingJoinRoom(room.roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onTagStoreUpdate = () => {
|
private onTagStoreUpdate = () => {
|
||||||
|
@ -168,30 +174,21 @@ 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.delete(roomId)) {
|
||||||
return pendingJoinRoomId !== roomId;
|
|
||||||
});
|
|
||||||
if (newPendingRoomJoin.length !== this.state.pendingRoomJoin.length) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
pendingRoomJoin: newPendingRoomJoin,
|
pendingRoomJoin: new Set<string>(this.state.pendingRoomJoin),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get hasPendingActions(): boolean {
|
|
||||||
return this.state.pendingRoomJoin.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private onOpenMenuClick = (ev: React.MouseEvent) => {
|
private onOpenMenuClick = (ev: React.MouseEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
@ -653,11 +650,11 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
{name}
|
{name}
|
||||||
{this.hasPendingActions && (
|
{this.state.pendingRoomJoin.size > 0 && (
|
||||||
<InlineSpinner>
|
<InlineSpinner>
|
||||||
<TooltipButton helpText={_t(
|
<TooltipButton helpText={_t(
|
||||||
"Currently joining %(count)s rooms",
|
"Currently joining %(count)s rooms",
|
||||||
{ count: this.state.pendingRoomJoin.length },
|
{ count: this.state.pendingRoomJoin.size },
|
||||||
)} />
|
)} />
|
||||||
</InlineSpinner>
|
</InlineSpinner>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -152,5 +152,5 @@ export enum Action {
|
||||||
/**
|
/**
|
||||||
* Fired when joining a room failed
|
* Fired when joining a room failed
|
||||||
*/
|
*/
|
||||||
JoinRoomError = "join_room",
|
JoinRoomError = "join_room_error",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue