From b74e4452ddf82564f6991bed6ad613cab7aeb6dd Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Thu, 17 Jun 2021 14:12:43 +0530 Subject: [PATCH] Move rightpanel to separate view and vm Signed-off-by: RMidhunSuresh --- .../session/rightpanel/RightPanelViewModel.js | 28 +++++++++++++++++++ .../ui/session/rightpanel/RightPanelView.js | 10 +++++++ 2 files changed, 38 insertions(+) create mode 100644 src/domain/session/rightpanel/RightPanelViewModel.js create mode 100644 src/platform/web/ui/session/rightpanel/RightPanelView.js diff --git a/src/domain/session/rightpanel/RightPanelViewModel.js b/src/domain/session/rightpanel/RightPanelViewModel.js new file mode 100644 index 00000000..2ab291bd --- /dev/null +++ b/src/domain/session/rightpanel/RightPanelViewModel.js @@ -0,0 +1,28 @@ +import {ViewModel} from "../../ViewModel.js"; +import {RoomDetailsViewModel} from "./RoomDetailsViewModel.js"; + +export class RightPanelViewModel extends ViewModel { + constructor(options) { + super(options); + this._room = options.room; + this._setupNavigation(); + } + + get roomDetailsViewModel() { return this._roomDetailsViewModel; } + + _setupNavigation() { + const details = this.navigation.observe("details"); + this.track(details.subscribe(() => this._toggleRoomDetailsPanel())); + this._toggleRoomDetailsPanel(); + } + + _toggleRoomDetailsPanel() { + this._roomDetailsViewModel = this.disposeTracked(this._roomDetailsViewModel); + const enable = !!this.navigation.path.get("details")?.value; + if (enable) { + const room = this._room; + this._roomDetailsViewModel = this.track(new RoomDetailsViewModel(this.childOptions({room}))); + } + this.emitChange("roomDetailsViewModel"); + } +} diff --git a/src/platform/web/ui/session/rightpanel/RightPanelView.js b/src/platform/web/ui/session/rightpanel/RightPanelView.js new file mode 100644 index 00000000..67a34012 --- /dev/null +++ b/src/platform/web/ui/session/rightpanel/RightPanelView.js @@ -0,0 +1,10 @@ +import {TemplateView} from "../../general/TemplateView.js"; +import {RoomDetailsView} from "./RoomDetailsView.js"; + +export class RightPanelView extends TemplateView { + render(t, vm) { + return t.div({ className: "RightPanelView"}, + t.mapView(vm => vm.roomDetailsViewModel, roomDetailsViewModel => roomDetailsViewModel ? new RoomDetailsView(roomDetailsViewModel) : null) + ); + } +}