also open the initial room in the room list

This commit is contained in:
Bruno Windels 2020-10-14 10:20:00 +02:00
parent 2b2392f375
commit 3d327b0875
2 changed files with 14 additions and 2 deletions

View file

@ -25,10 +25,20 @@ export class LeftPanelViewModel extends ViewModel {
super(options); super(options);
const {rooms} = options; const {rooms} = options;
this._roomTileViewModels = rooms.mapValues((room, emitChange) => { 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, room,
emitChange 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._roomListFilterMap = new ApplyMap(this._roomTileViewModels);
this._roomList = this._roomListFilterMap.sortValues((a, b) => a.compare(b)); this._roomList = this._roomListFilterMap.sortValues((a, b) => a.compare(b));
@ -39,7 +49,6 @@ export class LeftPanelViewModel extends ViewModel {
_setupNavigation() { _setupNavigation() {
const roomObservable = this.navigation.observe("room"); const roomObservable = this.navigation.observe("room");
this.track(roomObservable.subscribe(roomId => this._open(roomId))); this.track(roomObservable.subscribe(roomId => this._open(roomId)));
this._open(roomObservable.get());
const gridObservable = this.navigation.observe("rooms"); const gridObservable = this.navigation.observe("rooms");
this.gridEnabled = !!gridObservable.get(); this.gridEnabled = !!gridObservable.get();

View file

@ -31,6 +31,9 @@ export class RoomTileViewModel extends ViewModel {
this._wasUnreadWhenOpening = false; this._wasUnreadWhenOpening = false;
this._hidden = false; this._hidden = false;
this._url = this.urlRouter.openRoomActionUrl(this._room.id); this._url = this.urlRouter.openRoomActionUrl(this._room.id);
if (options.isOpen) {
this.open();
}
} }
get hidden() { get hidden() {