From 43868c4539209dc48afd7671c60d8957cf367fea Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 6 Sep 2021 15:17:09 +0100 Subject: [PATCH] Fix Space creation wizard go to my first room button behaviour --- src/components/structures/SpaceRoomView.tsx | 47 +++++---------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/src/components/structures/SpaceRoomView.tsx b/src/components/structures/SpaceRoomView.tsx index d32546f74d..9f21e69bb9 100644 --- a/src/components/structures/SpaceRoomView.tsx +++ b/src/components/structures/SpaceRoomView.tsx @@ -89,7 +89,7 @@ interface IProps { interface IState { phase: Phase; - createdRooms?: boolean; // internal state for the creation wizard + firstRoomId?: boolean; // internal state for the creation wizard showRightPanel: boolean; myMembership: string; } @@ -508,7 +508,7 @@ const SpaceSetupFirstRooms = ({ space, title, description, onFinished }) => { try { const isPublic = space.getJoinRule() === JoinRule.Public; const filteredRoomNames = roomNames.map(name => name.trim()).filter(Boolean); - await Promise.all(filteredRoomNames.map(name => { + const roomIds = await Promise.all(filteredRoomNames.map(name => { return createRoom({ createOpts: { preset: isPublic ? Preset.PublicChat : Preset.PrivateChat, @@ -523,7 +523,7 @@ const SpaceSetupFirstRooms = ({ space, title, description, onFinished }) => { suggested: true, }); })); - onFinished(filteredRoomNames.length > 0); + onFinished(roomIds[0]); } catch (e) { console.error("Failed to create initial space rooms", e); setError(_t("Failed to create initial space rooms")); @@ -533,7 +533,7 @@ const SpaceSetupFirstRooms = ({ space, title, description, onFinished }) => { let onClick = (ev) => { ev.preventDefault(); - onFinished(false); + onFinished(); }; let buttonLabel = _t("Skip for now"); if (roomNames.some(name => name.trim())) { @@ -588,7 +588,7 @@ const SpaceAddExistingRooms = ({ space, onFinished }) => { ; }; -const SpaceSetupPublicShare = ({ justCreatedOpts, space, onFinished, createdRooms }) => { +const SpaceSetupPublicShare = ({ justCreatedOpts, space, onFinished, firstRoomId }) => { return

{ _t("Share %(name)s", { name: justCreatedOpts?.createOpts?.name || space.name, @@ -601,7 +601,7 @@ const SpaceSetupPublicShare = ({ justCreatedOpts, space, onFinished, createdRoom
- { createdRooms ? _t("Go to my first room") : _t("Go to my space") } + { firstRoomId ? _t("Go to my first room") : _t("Go to my space") }

; @@ -844,35 +844,10 @@ export default class SpaceRoomView extends React.PureComponent { }; private goToFirstRoom = async () => { - // TODO actually go to the first room - - const childRooms = SpaceStore.instance.getChildRooms(this.props.space.roomId); - if (childRooms.length) { - const room = childRooms[0]; + if (this.state.firstRoomId) { defaultDispatcher.dispatch({ action: "view_room", - room_id: room.roomId, - }); - return; - } - - let suggestedRooms = SpaceStore.instance.suggestedRooms; - if (SpaceStore.instance.activeSpace !== this.props.space) { - // the space store has the suggested rooms loaded for a different space, fetch the right ones - suggestedRooms = (await SpaceStore.instance.fetchSuggestedRooms(this.props.space, 1)); - } - - if (suggestedRooms.length) { - const room = suggestedRooms[0]; - defaultDispatcher.dispatch({ - action: "view_room", - room_id: room.room_id, - room_alias: room.canonical_alias || room.aliases?.[0], - via_servers: room.viaServers, - oobData: { - avatarUrl: room.avatar_url, - name: room.name || room.canonical_alias || room.aliases?.[0] || _t("Empty room"), - }, + room_id: this.state.firstRoomId, }); return; } @@ -902,14 +877,14 @@ export default class SpaceRoomView extends React.PureComponent { _t("Let's create a room for each of them.") + "\n" + _t("You can add more later too, including already existing ones.") } - onFinished={(createdRooms: boolean) => this.setState({ phase: Phase.PublicShare, createdRooms })} + onFinished={(firstRoomId: boolean) => this.setState({ phase: Phase.PublicShare, firstRoomId })} />; case Phase.PublicShare: return ; case Phase.PrivateScope: @@ -931,7 +906,7 @@ export default class SpaceRoomView extends React.PureComponent { title={_t("What projects are you working on?")} description={_t("We'll create rooms for each of them. " + "You can add more later too, including already existing ones.")} - onFinished={(createdRooms: boolean) => this.setState({ phase: Phase.Landing, createdRooms })} + onFinished={(firstRoomId: boolean) => this.setState({ phase: Phase.Landing, firstRoomId })} />; case Phase.PrivateExistingRooms: return