From 3d327b087540d89f82e9eeefb9d3dc9feb754c42 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 14 Oct 2020 10:20:00 +0200 Subject: [PATCH] also open the initial room in the room list --- src/domain/session/leftpanel/LeftPanelViewModel.js | 13 +++++++++++-- src/domain/session/leftpanel/RoomTileViewModel.js | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index 15c30218..8dc3d224 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -25,10 +25,20 @@ export class LeftPanelViewModel extends ViewModel { super(options); const {rooms} = options; this._roomTileViewModels = rooms.mapValues((room, emitChange) => { - return new RoomTileViewModel(this.childOptions({ + const isOpen = this.navigation.path.get("room")?.value === room.id; + const vm = new RoomTileViewModel(this.childOptions({ + isOpen, room, emitChange })); + // need to also update the current vm here as + // we can't call `_open` from the ctor as the map + // is only populated when the view subscribes. + if (isOpen) { + this._currentTileVM?.close(); + this._currentTileVM = vm; + } + return vm; }); this._roomListFilterMap = new ApplyMap(this._roomTileViewModels); this._roomList = this._roomListFilterMap.sortValues((a, b) => a.compare(b)); @@ -39,7 +49,6 @@ export class LeftPanelViewModel extends ViewModel { _setupNavigation() { const roomObservable = this.navigation.observe("room"); this.track(roomObservable.subscribe(roomId => this._open(roomId))); - this._open(roomObservable.get()); const gridObservable = this.navigation.observe("rooms"); this.gridEnabled = !!gridObservable.get(); diff --git a/src/domain/session/leftpanel/RoomTileViewModel.js b/src/domain/session/leftpanel/RoomTileViewModel.js index a1e43d9f..09cb6372 100644 --- a/src/domain/session/leftpanel/RoomTileViewModel.js +++ b/src/domain/session/leftpanel/RoomTileViewModel.js @@ -31,6 +31,9 @@ export class RoomTileViewModel extends ViewModel { this._wasUnreadWhenOpening = false; this._hidden = false; this._url = this.urlRouter.openRoomActionUrl(this._room.id); + if (options.isOpen) { + this.open(); + } } get hidden() {