Skip to content

Commit 7b1a887

Browse files
committed
feat: use context menu in new room list
1 parent 1ad7e16 commit 7b1a887

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/components/views/rooms/RoomListPanel/RoomListItemView.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { RoomListItemMenuView } from "./RoomListItemMenuView";
1515
import { NotificationDecoration } from "../NotificationDecoration";
1616
import { RoomAvatarView } from "../../avatars/RoomAvatarView";
1717
import { useRovingTabIndex } from "../../../../accessibility/RovingTabIndex";
18+
import { RoomListItemContextMenuView } from "./RoomListItemContextMenuView";
1819

1920
interface RoomListItemViewProps extends React.HTMLAttributes<HTMLButtonElement> {
2021
/**
@@ -50,7 +51,19 @@ export const RoomListItemView = memo(function RoomListItemView({
5051
const isInvitation = vm.notificationState.invited;
5152
const isNotificationDecorationVisible = isInvitation || (!showHoverDecoration && vm.showNotificationDecoration);
5253

53-
return (
54+
const setIsMenuOpenMemoized = useCallback((isOpen: boolean) => {
55+
if (isOpen) {
56+
setIsMenuOpen(isOpen);
57+
} else {
58+
// To avoid icon blinking when closing the menu, we delay the state update
59+
setTimeout(() => setIsMenuOpen(isOpen), 0);
60+
// After closing the menu, we need to set the focus back to the button
61+
// 10ms because the focus moves to the body and we put back the focus on the button
62+
setTimeout(() => buttonRef.current?.focus(), 10);
63+
}
64+
}, []);
65+
66+
const content = (
5467
<button
5568
ref={ref}
5669
className={classNames("mx_RoomListItemView", {
@@ -95,20 +108,7 @@ export const RoomListItemView = memo(function RoomListItemView({
95108
<div className="mx_RoomListItemView_messagePreview">{vm.messagePreview}</div>
96109
</div>
97110
{showHoverMenu ? (
98-
<RoomListItemMenuView
99-
room={room}
100-
setMenuOpen={(isOpen) => {
101-
if (isOpen) {
102-
setIsMenuOpen(isOpen);
103-
} else {
104-
// To avoid icon blinking when closing the menu, we delay the state update
105-
setTimeout(() => setIsMenuOpen(isOpen), 0);
106-
// After closing the menu, we need to set the focus back to the button
107-
// 10ms because the focus moves to the body and we put back the focus on the button
108-
setTimeout(() => buttonRef.current?.focus(), 10);
109-
}
110-
}}
111-
/>
111+
<RoomListItemMenuView room={room} setMenuOpen={setIsMenuOpenMemoized} />
112112
) : (
113113
<>
114114
{/* aria-hidden because we summarise the unread count/notification status in a11yLabel variable */}
@@ -125,6 +125,14 @@ export const RoomListItemView = memo(function RoomListItemView({
125125
</Flex>
126126
</button>
127127
);
128+
129+
if (!vm.showContextMenu) return content;
130+
131+
return (
132+
<RoomListItemContextMenuView room={room} setMenuOpen={setIsMenuOpenMemoized}>
133+
{content}
134+
</RoomListItemContextMenuView>
135+
);
128136
});
129137

130138
/**

0 commit comments

Comments
 (0)