@@ -1,19 +1,25 @@
|
||||
import cons from '../state/cons';
|
||||
import navigation from '../state/navigation';
|
||||
import { selectTab, selectSpace } from '../action/navigation';
|
||||
|
||||
const listenRoomLeave = (roomId) => {
|
||||
const lRoomIndex = navigation.selectedSpacePath.indexOf(roomId);
|
||||
if (lRoomIndex === -1) return;
|
||||
if (lRoomIndex === 0) selectTab(cons.tabs.HOME);
|
||||
else selectSpace(navigation.selectedSpacePath[lRoomIndex - 1]);
|
||||
};
|
||||
import { selectTab, selectSpace, selectRoom } from '../action/navigation';
|
||||
|
||||
function initRoomListListener(roomList) {
|
||||
const listenRoomLeave = (roomId) => {
|
||||
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]);
|
||||
}
|
||||
};
|
||||
|
||||
roomList.on(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
|
||||
}
|
||||
function removeRoomListListener(roomList) {
|
||||
roomList.removeListener(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
|
||||
return () => {
|
||||
roomList.removeListener(cons.events.roomList.ROOM_LEAVED, listenRoomLeave);
|
||||
};
|
||||
}
|
||||
|
||||
export { initRoomListListener, removeRoomListListener };
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export { initRoomListListener };
|
||||
|
||||
Reference in New Issue
Block a user