mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-13 02:30:29 +03:00
Refector room list drawer
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
a62df536dd
commit
906fc2dd3d
6 changed files with 77 additions and 98 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -14,14 +14,17 @@ class AccountData extends EventEmitter {
|
|||
this._populateSpaceShortcut();
|
||||
this._listenEvents();
|
||||
|
||||
appDispatcher.register(this.roomActions.bind(this));
|
||||
appDispatcher.register(this.accountActions.bind(this));
|
||||
}
|
||||
|
||||
_getAccountData() {
|
||||
return this.matrixClient.getAccountData(cons.IN_CINNY_SPACES)?.getContent() || {};
|
||||
}
|
||||
|
||||
_populateSpaceShortcut() {
|
||||
this.spaceShortcut.clear();
|
||||
const spacesContent = this.matrixClient.getAccountData(cons.IN_CINNY_SPACES)?.getContent();
|
||||
const spacesContent = this._getAccountData();
|
||||
|
||||
if (!spacesContent) return;
|
||||
if (spacesContent?.shortcut === undefined) return;
|
||||
|
||||
spacesContent.shortcut.forEach((shortcut) => {
|
||||
|
|
@ -35,12 +38,12 @@ class AccountData extends EventEmitter {
|
|||
}
|
||||
|
||||
_updateSpaceShortcutData(shortcutList) {
|
||||
const spaceContent = this.matrixClient.getAccountData(cons.IN_CINNY_SPACES)?.getContent() || {};
|
||||
const spaceContent = this._getAccountData();
|
||||
spaceContent.shortcut = shortcutList;
|
||||
this.matrixClient.setAccountData(cons.IN_CINNY_SPACES, spaceContent);
|
||||
}
|
||||
|
||||
roomActions(action) {
|
||||
accountActions(action) {
|
||||
const actions = {
|
||||
[cons.actions.accountData.CREATE_SPACE_SHORTCUT]: () => {
|
||||
if (this.spaceShortcut.has(action.roomId)) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue