From a057ec18cabf5d6e264af03421c6af4f9e0013de Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 12 Nov 2021 15:45:14 +0000 Subject: [PATCH] Don't keep spinning if joining space child failed (#7129) --- src/components/structures/SpaceHierarchy.tsx | 23 +++++++++++--------- src/components/structures/SpaceRoomView.tsx | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/structures/SpaceHierarchy.tsx b/src/components/structures/SpaceHierarchy.tsx index a944ee7f67..f684c28ff0 100644 --- a/src/components/structures/SpaceHierarchy.tsx +++ b/src/components/structures/SpaceHierarchy.tsx @@ -68,7 +68,6 @@ interface IProps { initialText?: string; additionalButtons?: ReactNode; showRoom(cli: MatrixClient, hierarchy: RoomHierarchy, roomId: string, roomType?: RoomType): void; - joinRoom(cli: MatrixClient, hierarchy: RoomHierarchy, roomId: string): void; } interface ITileProps { @@ -78,7 +77,7 @@ interface ITileProps { numChildRooms?: number; hasPermissions?: boolean; onViewRoomClick(): void; - onJoinRoomClick(): void; + onJoinRoomClick(): Promise; onToggleClick?(): void; } @@ -115,9 +114,9 @@ const Tile: React.FC = ({ setBusy(true); ev.preventDefault(); ev.stopPropagation(); - onJoinRoomClick(); - setJoinedRoom(await awaitRoomDownSync(cli, room.room_id)); - setBusy(false); + onJoinRoomClick().then(() => awaitRoomDownSync(cli, room.room_id)).then(setJoinedRoom).finally(() => { + setBusy(false); + }); }; let button; @@ -141,7 +140,7 @@ const Tile: React.FC = ({ > { _t("View") } ; - } else if (onJoinClick) { + } else { button = { +export const joinRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: string): Promise => { // Don't let the user view a room they won't be able to either peek or join: // fail earlier so they don't have to click back to the directory. if (cli.isGuest()) { @@ -351,11 +350,15 @@ export const joinRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st return; } - cli.joinRoom(roomId, { + const prom = cli.joinRoom(roomId, { viaServers: Array.from(hierarchy.viaMap.get(roomId) || []), - }).catch(err => { + }); + + prom.catch(err => { RoomViewStore.showJoinRoomError(err, roomId); }); + + return prom; }; interface IHierarchyLevelProps { @@ -365,7 +368,7 @@ interface IHierarchyLevelProps { parents: Set; selectedMap?: Map>; onViewRoomClick(roomId: string, roomType?: RoomType): void; - onJoinRoomClick(roomId: string): void; + onJoinRoomClick(roomId: string): Promise; onToggleClick?(parentId: string, childId: string): void; } diff --git a/src/components/structures/SpaceRoomView.tsx b/src/components/structures/SpaceRoomView.tsx index ddf8f9225b..becd05b9c9 100644 --- a/src/components/structures/SpaceRoomView.tsx +++ b/src/components/structures/SpaceRoomView.tsx @@ -55,7 +55,7 @@ import { showSpaceInvite, showSpaceSettings, } from "../../utils/space"; -import SpaceHierarchy, { joinRoom, showRoom } from "./SpaceHierarchy"; +import SpaceHierarchy, { showRoom } from "./SpaceHierarchy"; import MemberAvatar from "../views/avatars/MemberAvatar"; import SpaceStore from "../../stores/spaces/SpaceStore"; import FacePile from "../views/elements/FacePile"; @@ -508,7 +508,7 @@ const SpaceLanding = ({ space }: { space: Room }) => { ) } - + ; };