when opening room, focus in grid if already open

This commit is contained in:
Bruno Windels 2020-10-07 13:18:19 +02:00
parent 1ff6d36ec3
commit b9d2da736a
2 changed files with 11 additions and 4 deletions

View file

@ -34,6 +34,9 @@ export class RoomGridViewModel extends ViewModel {
} }
setFocusedIndex(idx) { setFocusedIndex(idx) {
if (idx === this._selectedIndex) {
return;
}
const oldItem = this._viewModels[this._selectedIndex]; const oldItem = this._viewModels[this._selectedIndex];
oldItem?.tileVM?.close(); oldItem?.tileVM?.close();
this._selectedIndex = idx; this._selectedIndex = idx;
@ -69,8 +72,8 @@ export class RoomGridViewModel extends ViewModel {
/** /**
* @package * @package
*/ */
hasRoomId(roomId) { roomIndex(roomId) {
return this._viewModels.some(vms => vms?.vm._room.id === roomId); return this._viewModels.findIndex(vms => vms?.vm._room.id === roomId);
} }
/** /**

View file

@ -111,8 +111,12 @@ export class SessionViewModel extends ViewModel {
_openRoom(room, roomTileVM) { _openRoom(room, roomTileVM) {
// for now, we don't support having the same room opened more than once, // for now, we don't support having the same room opened more than once,
// so bail out if we already have the room open // so bail out if we already have the room open
if (this._gridViewModel?.hasRoomId(room.id)) { if (this._gridViewModel) {
const roomIndex = this._gridViewModel.roomIndex(room.id);
if (roomIndex >= 0) {
this._gridViewModel.setFocusedIndex(roomIndex);
return; return;
}
} else if (this._currentRoomViewModel?._room.id === room.id) { } else if (this._currentRoomViewModel?._room.id === room.id) {
return; return;
} }