55 * Please see LICENSE files in the repository root for full details.
66 */
77
8- import React , { useCallback , useRef , useState , type JSX } from "react" ;
9- import { type Room } from "matrix-js-sdk/src/matrix" ;
8+ import React , { type JSX , useCallback , useRef , useState } from "react" ;
109import { type ScrollIntoViewLocation } from "react-virtuoso" ;
1110import { isEqual } from "lodash" ;
1211
@@ -18,6 +17,8 @@ import { type FilterKey } from "../../../../stores/room-list-v3/skip-list/filter
1817import { getKeyBindingsManager } from "../../../../KeyBindingsManager" ;
1918import { KeyBindingAction } from "../../../../accessibility/KeyboardShortcuts" ;
2019import { Landmark , LandmarkNavigation } from "../../../../accessibility/LandmarkNavigation" ;
20+ import { isRoomListSectionHeader , type RoomListEntry } from "../../../../stores/room-list-v3/RoomListStoreV3.ts" ;
21+ import { RoomListSectionHeaderView } from "./RoomListSectionHeaderView.tsx" ;
2122
2223interface RoomListProps {
2324 /**
@@ -37,6 +38,11 @@ const ROOM_LIST_ITEM_HEIGHT = 48;
3738 * We would likely need to simplify the item content to improve this case.
3839 */
3940const EXTENDED_VIEWPORT_HEIGHT = 25 * ROOM_LIST_ITEM_HEIGHT ;
41+
42+ const getItemKey = ( item : RoomListEntry ) : string => {
43+ return isRoomListSectionHeader ( item ) ? item . key : item . roomId ;
44+ } ;
45+
4046/**
4147 * A virtualized list of rooms.
4248 */
@@ -48,38 +54,38 @@ export function RoomList({ vm: { roomsResult, activeIndex } }: RoomListProps): J
4854 const getItemComponent = useCallback (
4955 (
5056 index : number ,
51- item : Room ,
57+ item : RoomListEntry ,
5258 context : ListContext < {
5359 spaceId : string ;
5460 filterKeys : FilterKey [ ] | undefined ;
5561 } > ,
5662 onFocus : ( e : React . FocusEvent ) => void ,
5763 ) : JSX . Element => {
58- const itemKey = item . roomId ;
64+ const itemKey = getItemKey ( item ) ;
5965 const isRovingItem = itemKey === context . tabIndexKey ;
6066 const isFocused = isRovingItem && context . focused ;
6167 const isSelected = activeIndex === index ;
62- return (
63- < RoomListItemView
64- room = { item }
65- key = { itemKey }
66- isSelected = { isSelected }
67- isFocused = { isFocused }
68- tabIndex = { isRovingItem ? 0 : - 1 }
69- roomIndex = { index }
70- roomCount = { roomCount }
71- onFocus = { onFocus }
72- listIsScrolling = { isScrolling }
73- />
74- ) ;
68+ if ( isRoomListSectionHeader ( item ) ) {
69+ return < RoomListSectionHeaderView section = { item } /> ;
70+ } else {
71+ return (
72+ < RoomListItemView
73+ room = { item }
74+ key = { itemKey }
75+ isSelected = { isSelected }
76+ isFocused = { isFocused }
77+ tabIndex = { isRovingItem ? 0 : - 1 }
78+ roomIndex = { index }
79+ roomCount = { roomCount }
80+ onFocus = { onFocus }
81+ listIsScrolling = { isScrolling }
82+ />
83+ ) ;
84+ }
7585 } ,
7686 [ activeIndex , roomCount , isScrolling ] ,
7787 ) ;
7888
79- const getItemKey = useCallback ( ( item : Room ) : string => {
80- return item . roomId ;
81- } , [ ] ) ;
82-
8389 const scrollIntoViewOnChange = useCallback (
8490 ( params : {
8591 context : ListContext < { spaceId : string ; filterKeys : FilterKey [ ] | undefined } > ;
0 commit comments