Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix home/all rooms context menu in space panel (#11350)
Browse files Browse the repository at this point in the history
* Fix home/all rooms context menu in space panel

* Fix tests
  • Loading branch information
t3chguy authored Aug 1, 2023
1 parent 5d9f5cc commit 2f2067e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/components/views/context_menus/SpaceContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ import PosthogTrackers from "../../../PosthogTrackers";
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";

interface IProps extends IContextMenuProps {
space: Room;
space?: Room;
hideHeader?: boolean;
}

const SpaceContextMenu: React.FC<IProps> = ({ space, hideHeader, onFinished, ...props }) => {
const cli = useContext(MatrixClientContext);
const userId = cli.getUserId()!;
const userId = cli.getSafeUserId();
const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms");
const elementCallVideoRoomsEnabled = useFeatureEnabled("feature_element_call_video_rooms");

if (!space) return null;

let inviteOption: JSX.Element | null = null;
if (space.getJoinRule() === "public" || space.canInvite(userId)) {
Expand Down Expand Up @@ -135,9 +139,6 @@ const SpaceContextMenu: React.FC<IProps> = ({ space, hideHeader, onFinished, ...
);
}

const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms");
const elementCallVideoRoomsEnabled = useFeatureEnabled("feature_element_call_video_rooms");

const hasPermissionToAddSpaceChild = space.currentState.maySendStateEvent(EventType.SpaceChild, userId);
const canAddRooms = hasPermissionToAddSpaceChild && shouldShowComponent(UIComponent.CreateRooms);
const canAddVideoRooms = canAddRooms && videoRoomsEnabled;
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/spaces/SpaceTreeLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const SpaceButton: React.FC<IButtonProps> = ({
}

let contextMenu: JSX.Element | undefined;
if (space && menuDisplayed && handle.current && ContextMenuComponent) {
if (menuDisplayed && handle.current && ContextMenuComponent) {
contextMenu = (
<ContextMenuComponent
{...toRightOf(handle.current.getBoundingClientRect(), 0)}
Expand Down
2 changes: 2 additions & 0 deletions test/components/views/context_menus/SpaceContextMenu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe("<SpaceContextMenu />", () => {

const mockClient = {
getUserId: jest.fn().mockReturnValue(userId),
getSafeUserId: jest.fn().mockReturnValue(userId),
} as unknown as Mocked<MatrixClient>;

const makeMockSpace = (props = {}) =>
Expand Down Expand Up @@ -86,6 +87,7 @@ describe("<SpaceContextMenu />", () => {
beforeEach(() => {
jest.resetAllMocks();
mockClient.getUserId.mockReturnValue(userId);
mockClient.getSafeUserId.mockReturnValue(userId);
});

it("renders menu correctly", () => {
Expand Down

0 comments on commit 2f2067e

Please sign in to comment.