when opening room, focus in grid if already open
This commit is contained in:
parent
1ff6d36ec3
commit
b9d2da736a
2 changed files with 11 additions and 4 deletions
|
@ -34,6 +34,9 @@ export class RoomGridViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
setFocusedIndex(idx) {
|
||||
if (idx === this._selectedIndex) {
|
||||
return;
|
||||
}
|
||||
const oldItem = this._viewModels[this._selectedIndex];
|
||||
oldItem?.tileVM?.close();
|
||||
this._selectedIndex = idx;
|
||||
|
@ -69,8 +72,8 @@ export class RoomGridViewModel extends ViewModel {
|
|||
/**
|
||||
* @package
|
||||
*/
|
||||
hasRoomId(roomId) {
|
||||
return this._viewModels.some(vms => vms?.vm._room.id === roomId);
|
||||
roomIndex(roomId) {
|
||||
return this._viewModels.findIndex(vms => vms?.vm._room.id === roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,8 +111,12 @@ export class SessionViewModel extends ViewModel {
|
|||
_openRoom(room, roomTileVM) {
|
||||
// for now, we don't support having the same room opened more than once,
|
||||
// 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;
|
||||
}
|
||||
} else if (this._currentRoomViewModel?._room.id === room.id) {
|
||||
return;
|
||||
}
|
||||
|
|
Reference in a new issue