RoomListViewModel: Track the index of the active room in the list (#29519)

* Introduce a hook to track active room

This hook simply keeps a state which tracks the index of the active room
in the list of rooms passed through props. This index will be recomputed
if the active rooms changes or if the list itself changed.

* Use hook in the view model

* Write tests

* Fix broken tests
This commit is contained in:
R Midhun Suresh
2025-03-18 18:19:10 +05:30
committed by GitHub
parent 7de54a385e
commit 839329b52a
7 changed files with 101 additions and 0 deletions
@@ -31,6 +31,7 @@ describe("<EmptyRoomList />", () => {
canCreateRoom: true,
shouldShowMessagePreview: false,
toggleMessagePreview: jest.fn(),
activeIndex: undefined,
};
});
@@ -40,6 +40,7 @@ describe("<RoomList />", () => {
createRoom: jest.fn(),
createChatRoom: jest.fn(),
canCreateRoom: true,
activeIndex: undefined,
};
// Needed to render a room list cell
@@ -34,6 +34,7 @@ describe("<RoomListPrimaryFilters />", () => {
activeSortOption: SortOption.Activity,
shouldShowMessagePreview: false,
toggleMessagePreview: jest.fn(),
activeIndex: undefined,
};
});
@@ -35,6 +35,7 @@ describe("<RoomListView />", () => {
canCreateRoom: true,
toggleMessagePreview: jest.fn(),
shouldShowMessagePreview: false,
activeIndex: undefined,
};
const matrixClient = stubClient();