Merge pull request #6108 from matrix-org/gsouquet/fix/17473

This commit is contained in:
Germain 2021-05-27 09:51:59 +01:00 committed by GitHub
commit fd7bc9755a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 20 deletions

View file

@ -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>
)} )}

View file

@ -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",
} }