Files
cinny/src/client/state/navigation.js
T

76 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-07-28 18:45:52 +05:30
import EventEmitter from 'events';
import appDispatcher from '../dispatcher';
import cons from './cons';
class Navigation extends EventEmitter {
constructor() {
super();
2022-05-14 08:24:21 +05:30
this.rawModelStack = [];
2021-07-28 18:45:52 +05:30
}
2022-05-14 08:24:21 +05:30
get isRawModalVisible() {
return this.rawModelStack.length > 0;
}
2021-12-11 10:50:34 +05:30
setIsRawModalVisible(visible) {
2022-05-14 08:24:21 +05:30
if (visible) this.rawModelStack.push(true);
else this.rawModelStack.pop();
2021-12-11 10:50:34 +05:30
}
2021-07-28 18:45:52 +05:30
navigate(action) {
const actions = {
2022-02-20 20:17:13 +05:30
[cons.actions.navigation.OPEN_SPACE_ADDEXISTING]: () => {
this.emit(cons.events.navigation.SPACE_ADDEXISTING_OPENED, action.roomId, action.spaces);
2022-02-20 20:17:13 +05:30
},
2021-08-31 18:43:31 +05:30
[cons.actions.navigation.OPEN_CREATE_ROOM]: () => {
2022-02-26 21:00:52 +05:30
this.emit(
cons.events.navigation.CREATE_ROOM_OPENED,
action.isSpace,
action.parentId,
);
2021-07-28 18:45:52 +05:30
},
2022-05-03 16:01:50 +05:30
[cons.actions.navigation.OPEN_JOIN_ALIAS]: () => {
this.emit(
cons.events.navigation.JOIN_ALIAS_OPENED,
action.term,
);
},
2021-07-28 18:45:52 +05:30
[cons.actions.navigation.OPEN_INVITE_USER]: () => {
this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId, action.searchTerm);
2021-07-28 18:45:52 +05:30
},
2021-10-18 17:25:52 +02:00
[cons.actions.navigation.OPEN_PROFILE_VIEWER]: () => {
this.emit(cons.events.navigation.PROFILE_VIEWER_OPENED, action.userId, action.roomId);
},
2021-12-10 17:22:53 +05:30
[cons.actions.navigation.OPEN_SEARCH]: () => {
this.emit(
cons.events.navigation.SEARCH_OPENED,
action.term,
);
},
2022-01-11 20:46:41 +05:30
[cons.actions.navigation.OPEN_REUSABLE_CONTEXT_MENU]: () => {
this.emit(
cons.events.navigation.REUSABLE_CONTEXT_MENU_OPENED,
action.placement,
action.cords,
action.render,
action.afterClose,
2022-01-11 20:46:41 +05:30
);
},
2022-03-31 20:39:05 +05:30
[cons.actions.navigation.OPEN_REUSABLE_DIALOG]: () => {
this.emit(
cons.events.navigation.REUSABLE_DIALOG_OPENED,
action.title,
action.render,
action.afterClose,
);
},
2021-07-28 18:45:52 +05:30
};
actions[action.type]?.();
}
}
const navigation = new Navigation();
appDispatcher.register(navigation.navigate.bind(navigation));
export default navigation;