mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-05 15:00:30 +03:00
Add recent opened room in search
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
77818f9342
commit
413188c995
2 changed files with 60 additions and 20 deletions
|
|
@ -11,6 +11,7 @@ class Navigation extends EventEmitter {
|
|||
this.selectedSpacePath = [cons.tabs.HOME];
|
||||
|
||||
this.selectedRoomId = null;
|
||||
this.recentRooms = [];
|
||||
}
|
||||
|
||||
_setSpacePath(roomId) {
|
||||
|
|
@ -26,6 +27,24 @@ class Navigation extends EventEmitter {
|
|||
this.selectedSpacePath.push(roomId);
|
||||
}
|
||||
|
||||
removeRecentRoom(roomId) {
|
||||
if (typeof roomId !== 'string') return;
|
||||
const roomIdIndex = this.recentRooms.indexOf(roomId);
|
||||
if (roomIdIndex >= 0) {
|
||||
this.recentRooms.splice(roomIdIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
addRecentRoom(roomId) {
|
||||
if (typeof roomId !== 'string') return;
|
||||
|
||||
this.removeRecentRoom(roomId);
|
||||
this.recentRooms.push(roomId);
|
||||
if (this.recentRooms.length > 10) {
|
||||
this.recentRooms.splice(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
navigate(action) {
|
||||
const actions = {
|
||||
[cons.actions.navigation.SELECT_TAB]: () => {
|
||||
|
|
@ -50,6 +69,8 @@ class Navigation extends EventEmitter {
|
|||
[cons.actions.navigation.SELECT_ROOM]: () => {
|
||||
const prevSelectedRoomId = this.selectedRoomId;
|
||||
this.selectedRoomId = action.roomId;
|
||||
this.addRecentRoom(prevSelectedRoomId);
|
||||
this.removeRecentRoom(this.selectedRoomId);
|
||||
this.emit(
|
||||
cons.events.navigation.ROOM_SELECTED,
|
||||
this.selectedRoomId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue