diff --git a/src/components/structures/SpaceRoomView.tsx b/src/components/structures/SpaceRoomView.tsx index 695fa7a749e..ec439816130 100644 --- a/src/components/structures/SpaceRoomView.tsx +++ b/src/components/structures/SpaceRoomView.tsx @@ -1,5 +1,5 @@ /* -Copyright 2021 The Matrix.org Foundation C.I.C. +Copyright 2021-2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,35 +14,31 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { RefObject, useContext, useRef, useState } from "react"; import { EventType, RoomType } from "matrix-js-sdk/src/@types/event"; import { JoinRule, Preset } from "matrix-js-sdk/src/@types/partials"; -import { Room, RoomEvent } from "matrix-js-sdk/src/models/room"; import { logger } from "matrix-js-sdk/src/logger"; +import { Room, RoomEvent } from "matrix-js-sdk/src/models/room"; +import React, { RefObject, useContext, useEffect, useRef, useState } from "react"; import MatrixClientContext from "../../contexts/MatrixClientContext"; -import RoomAvatar from "../views/avatars/RoomAvatar"; -import { _t } from "../../languageHandler"; -import AccessibleButton from "../views/elements/AccessibleButton"; -import RoomName from "../views/elements/RoomName"; -import RoomTopic from "../views/elements/RoomTopic"; -import { inviteMultipleToRoom, showRoomInviteDialog } from "../../RoomInvite"; -import { useFeatureEnabled } from "../../hooks/useSettings"; import createRoom, { IOpts } from "../../createRoom"; -import Field from "../views/elements/Field"; -import withValidation from "../views/elements/Validation"; -import * as Email from "../../email"; -import defaultDispatcher from "../../dispatcher/dispatcher"; +import { shouldShowComponent } from "../../customisations/helpers/UIComponents"; import { Action } from "../../dispatcher/actions"; -import ResizeNotifier from "../../utils/ResizeNotifier"; -import MainSplit from './MainSplit'; -import ErrorBoundary from "../views/elements/ErrorBoundary"; +import defaultDispatcher from "../../dispatcher/dispatcher"; import { ActionPayload } from "../../dispatcher/payloads"; -import RightPanel from "./RightPanel"; +import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload"; +import * as Email from "../../email"; +import { useMyRoomMembership } from "../../hooks/useRoomMembers"; +import { useFeatureEnabled } from "../../hooks/useSettings"; +import { useStateArray } from "../../hooks/useStateArray"; +import { _t } from "../../languageHandler"; +import PosthogTrackers from "../../PosthogTrackers"; +import { inviteMultipleToRoom, showRoomInviteDialog } from "../../RoomInvite"; +import { UIComponent } from "../../settings/UIFeature"; +import { UPDATE_EVENT } from "../../stores/AsyncStore"; import RightPanelStore from "../../stores/right-panel/RightPanelStore"; import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases"; -import { useStateArray } from "../../hooks/useStateArray"; -import SpacePublicShare from "../views/spaces/SpacePublicShare"; +import ResizeNotifier from "../../utils/ResizeNotifier"; import { shouldShowSpaceInvite, shouldShowSpaceSettings, @@ -52,29 +48,33 @@ import { showSpaceInvite, showSpaceSettings, } from "../../utils/space"; -import SpaceHierarchy, { showRoom } from "./SpaceHierarchy"; -import RoomFacePile from "../views/elements/RoomFacePile"; +import RoomAvatar from "../views/avatars/RoomAvatar"; +import { BetaPill } from "../views/beta/BetaCard"; +import IconizedContextMenu, { + IconizedContextMenuOption, + IconizedContextMenuOptionList, +} from "../views/context_menus/IconizedContextMenu"; import { AddExistingToSpace, defaultDmsRenderer, defaultRoomsRenderer, } from "../views/dialogs/AddExistingToSpaceDialog"; -import { ChevronFace, ContextMenuButton, useContextMenu } from "./ContextMenu"; -import IconizedContextMenu, { - IconizedContextMenuOption, - IconizedContextMenuOptionList, -} from "../views/context_menus/IconizedContextMenu"; +import AccessibleButton from "../views/elements/AccessibleButton"; import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton"; -import { BetaPill } from "../views/beta/BetaCard"; -import { SpaceFeedbackPrompt } from "../views/spaces/SpaceCreateMenu"; +import ErrorBoundary from "../views/elements/ErrorBoundary"; +import Field from "../views/elements/Field"; +import RoomFacePile from "../views/elements/RoomFacePile"; +import RoomName from "../views/elements/RoomName"; +import RoomTopic from "../views/elements/RoomTopic"; +import withValidation from "../views/elements/Validation"; import RoomInfoLine from "../views/rooms/RoomInfoLine"; import RoomPreviewCard from "../views/rooms/RoomPreviewCard"; -import { useMyRoomMembership } from "../../hooks/useRoomMembers"; -import { shouldShowComponent } from "../../customisations/helpers/UIComponents"; -import { UIComponent } from "../../settings/UIFeature"; -import { UPDATE_EVENT } from "../../stores/AsyncStore"; -import PosthogTrackers from "../../PosthogTrackers"; -import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload"; +import { SpaceFeedbackPrompt } from "../views/spaces/SpaceCreateMenu"; +import SpacePublicShare from "../views/spaces/SpacePublicShare"; +import { ChevronFace, ContextMenuButton, useContextMenu } from "./ContextMenu"; +import MainSplit from './MainSplit'; +import RightPanel from "./RightPanel"; +import SpaceHierarchy, { showRoom } from "./SpaceHierarchy"; interface IProps { space: Room; @@ -190,11 +190,25 @@ const SpaceLandingAddButton = ({ space }) => { ; }; +function storeIsShowingSpaceMembers(space: Room): boolean { + return RightPanelStore.instance.isOpenForRoom(space.roomId) && + RightPanelStore.instance.currentCardForRoom(space.roomId)?.phase === RightPanelPhases.SpaceMemberList; +} + const SpaceLanding = ({ space }: { space: Room }) => { const cli = useContext(MatrixClientContext); const myMembership = useMyRoomMembership(space); const userId = cli.getUserId(); + const [isShowingMembers, setIsShowingMembers] = useState(storeIsShowingSpaceMembers(space)); + useEffect(() => { + const listener = () => setIsShowingMembers(storeIsShowingSpaceMembers(space)); + RightPanelStore.instance.addListener(UPDATE_EVENT, listener); + return () => { + RightPanelStore.instance.removeListener(UPDATE_EVENT, listener); + }; + }, [space]); + let inviteButton; if (shouldShowSpaceInvite(space) && shouldShowComponent(UIComponent.InviteUsers)) { inviteButton = ( @@ -249,7 +263,12 @@ const SpaceLanding = ({ space }: { space: Room }) => {
- + { inviteButton } { settingsButton }