From 5aacf85166d2fc7d9224140f5b50a7e9fad1e578 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 12 Aug 2020 17:40:41 +0200 Subject: [PATCH] mark room tile as active when clicked --- src/domain/session/SessionViewModel.js | 13 +++++++--- .../session/roomlist/RoomTileViewModel.js | 25 ++++++++++++++++--- src/ui/web/session/RoomTile.js | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index 3737ebac..879c5e26 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -28,12 +28,13 @@ export class SessionViewModel extends ViewModel { sync: sessionContainer.sync, reconnector: sessionContainer.reconnector }))); + this._currentRoomTileViewModel = null; this._currentRoomViewModel = null; - const roomTileVMs = this._session.rooms.mapValues((room, emitUpdate) => { + const roomTileVMs = this._session.rooms.mapValues((room, emitChange) => { return new RoomTileViewModel({ room, - emitUpdate, - emitOpen: room => this._openRoom(room) + emitChange, + emitOpen: this._openRoom.bind(this) }); }); this._roomList = roomTileVMs.sortValues((a, b) => a.compare(b)); @@ -62,7 +63,11 @@ export class SessionViewModel extends ViewModel { } } - _openRoom(room) { + _openRoom(room, roomTileVM) { + if (this._currentRoomTileViewModel) { + this._currentRoomTileViewModel.close(); + } + this._currentRoomTileViewModel = roomTileVM; if (this._currentRoomViewModel) { this._currentRoomViewModel = this.disposeTracked(this._currentRoomViewModel); } diff --git a/src/domain/session/roomlist/RoomTileViewModel.js b/src/domain/session/roomlist/RoomTileViewModel.js index 1de7f1d8..d1585262 100644 --- a/src/domain/session/roomlist/RoomTileViewModel.js +++ b/src/domain/session/roomlist/RoomTileViewModel.js @@ -15,20 +15,33 @@ limitations under the License. */ import {avatarInitials} from "../avatar.js"; +import {ViewModel} from "../../ViewModel.js"; -export class RoomTileViewModel { +export class RoomTileViewModel extends ViewModel { // we use callbacks to parent VM instead of emit because // it would be annoying to keep track of subscriptions in // parent for all RoomTileViewModels // emitUpdate is ObservableMap/ObservableList update mechanism - constructor({room, emitUpdate, emitOpen}) { + constructor(options) { + super(options); + const {room, emitOpen} = options; this._room = room; - this._emitUpdate = emitUpdate; this._emitOpen = emitOpen; + this._isOpen = false; + } + + // called by parent for now (later should integrate with router) + close() { + if (this._isOpen) { + this._isOpen = false; + this.emitChange("isOpen"); + } } open() { - this._emitOpen(this._room); + this._isOpen = true; + this.emitChange("isOpen"); + this._emitOpen(this._room, this); } compare(other) { @@ -36,6 +49,10 @@ export class RoomTileViewModel { return this._room.name.localeCompare(other._room.name); } + get isOpen() { + return this._isOpen; + } + get name() { return this._room.name; } diff --git a/src/ui/web/session/RoomTile.js b/src/ui/web/session/RoomTile.js index 036fca1b..bdce01cc 100644 --- a/src/ui/web/session/RoomTile.js +++ b/src/ui/web/session/RoomTile.js @@ -18,7 +18,7 @@ import {TemplateView} from "../general/TemplateView.js"; export class RoomTile extends TemplateView { render(t) { - return t.li([ + return t.li({"className": {"active": vm => vm.isOpen}}, [ t.div({className: "avatar medium"}, vm => vm.avatarInitials), t.div({className: "description"}, t.div({className: "name"}, vm => vm.name)) ]);