2021-07-28 22:15:52 +09:00
|
|
|
import EventEmitter from 'events';
|
|
|
|
import appDispatcher from '../dispatcher';
|
|
|
|
import cons from './cons';
|
|
|
|
|
|
|
|
class Navigation extends EventEmitter {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2021-08-31 00:42:24 +09:00
|
|
|
this.activeTab = 'home';
|
2021-08-24 19:01:20 +09:00
|
|
|
this.activeRoomId = null;
|
2021-07-28 22:15:52 +09:00
|
|
|
this.isPeopleDrawerVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
getActiveTab() {
|
|
|
|
return this.activeTab;
|
|
|
|
}
|
|
|
|
|
2021-08-24 19:01:20 +09:00
|
|
|
getActiveRoomId() {
|
|
|
|
return this.activeRoomId;
|
2021-07-28 22:15:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
navigate(action) {
|
|
|
|
const actions = {
|
|
|
|
[cons.actions.navigation.CHANGE_TAB]: () => {
|
|
|
|
this.activeTab = action.tabId;
|
|
|
|
this.emit(cons.events.navigation.TAB_CHANGED, this.activeTab);
|
|
|
|
},
|
|
|
|
[cons.actions.navigation.SELECT_ROOM]: () => {
|
2021-08-31 00:42:24 +09:00
|
|
|
const prevActiveRoomId = this.activeRoomId;
|
2021-08-24 19:01:20 +09:00
|
|
|
this.activeRoomId = action.roomId;
|
2021-08-31 00:42:24 +09:00
|
|
|
this.emit(cons.events.navigation.ROOM_SELECTED, this.activeRoomId, prevActiveRoomId);
|
2021-07-28 22:15:52 +09:00
|
|
|
},
|
|
|
|
[cons.actions.navigation.TOGGLE_PEOPLE_DRAWER]: () => {
|
|
|
|
this.isPeopleDrawerVisible = !this.isPeopleDrawerVisible;
|
|
|
|
this.emit(cons.events.navigation.PEOPLE_DRAWER_TOGGLED, this.isPeopleDrawerVisible);
|
|
|
|
},
|
|
|
|
[cons.actions.navigation.OPEN_INVITE_LIST]: () => {
|
|
|
|
this.emit(cons.events.navigation.INVITE_LIST_OPENED);
|
|
|
|
},
|
2021-08-31 22:13:31 +09:00
|
|
|
[cons.actions.navigation.OPEN_PUBLIC_ROOMS]: () => {
|
|
|
|
this.emit(cons.events.navigation.PUBLIC_ROOMS_OPENED, action.searchTerm);
|
2021-07-28 22:15:52 +09:00
|
|
|
},
|
2021-08-31 22:13:31 +09:00
|
|
|
[cons.actions.navigation.OPEN_CREATE_ROOM]: () => {
|
|
|
|
this.emit(cons.events.navigation.CREATE_ROOM_OPENED);
|
2021-07-28 22:15:52 +09:00
|
|
|
},
|
|
|
|
[cons.actions.navigation.OPEN_INVITE_USER]: () => {
|
2021-08-08 13:53:26 +09:00
|
|
|
this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId, action.searchTerm);
|
2021-07-28 22:15:52 +09:00
|
|
|
},
|
|
|
|
[cons.actions.navigation.OPEN_SETTINGS]: () => {
|
|
|
|
this.emit(cons.events.navigation.SETTINGS_OPENED);
|
|
|
|
},
|
2021-08-14 13:49:29 +09:00
|
|
|
[cons.actions.navigation.OPEN_EMOJIBOARD]: () => {
|
|
|
|
this.emit(
|
|
|
|
cons.events.navigation.EMOJIBOARD_OPENED,
|
|
|
|
action.cords, action.requestEmojiCallback,
|
|
|
|
);
|
|
|
|
},
|
2021-08-16 21:07:29 +09:00
|
|
|
[cons.actions.navigation.OPEN_READRECEIPTS]: () => {
|
|
|
|
this.emit(
|
|
|
|
cons.events.navigation.READRECEIPTS_OPENED,
|
|
|
|
action.roomId,
|
|
|
|
action.eventId,
|
|
|
|
);
|
|
|
|
},
|
2021-07-28 22:15:52 +09:00
|
|
|
};
|
|
|
|
actions[action.type]?.();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const navigation = new Navigation();
|
|
|
|
appDispatcher.register(navigation.navigate.bind(navigation));
|
|
|
|
|
|
|
|
export default navigation;
|