Files
cinny/src/client/event/roomList.js
T
Ajay Bura 7e28aa1474 Update sidebar on room/space switch (#768)
* Select last room on space/tab change (#353)

* Update sidbar on room select from search (#374)

* Select last room on space/tab change (#353)

* Update sidbar on room select from search (#374)

* Fix wrong space gets selected with some rooms

* Fix auto select room in categorized space

* Fix room remain selected on leave

* Fix leaved room appear in category & search

* Remove globally exposed vars

* Hide pin spaces from home

* Fix selecting dm always open dm tab

* Order category by AtoZ (#769)

Co-authored-by: Krishan <33421343+kfiven@users.noreply.github.com>
2022-08-20 20:51:37 +05:30

39 lines
1.1 KiB
JavaScript

import cons from '../state/cons';
import navigation from '../state/navigation';
import { selectTab, selectSpace, selectRoom } from '../action/navigation';
function initRoomListListener(roomList) {
const listenRoomLeave = (roomId) => {
const parents = roomList.roomIdToParents.get(roomId);
if (parents) {
[...parents].forEach((pId) => {
const data = navigation.spaceToRoom.get(pId);
if (data?.roomId === roomId) {
navigation.spaceToRoom.delete(pId);
}
});
}
if (navigation.selectedRoomId === roomId) {
selectRoom(null);
}
if (navigation.selectedSpacePath.includes(roomId)) {
const idIndex = navigation.selectedSpacePath.indexOf(roomId);
if (idIndex === 0) selectTab(cons.tabs.HOME);
else selectSpace(navigation.selectedSpacePath[idIndex - 1]);
}
navigation.removeRecentRoom(roomId);
};
roomList.on(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
return () => {
roomList.removeListener(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
};
}
// eslint-disable-next-line import/prefer-default-export
export { initRoomListListener };