Move rightpanel to separate view and vm

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-06-17 14:12:43 +05:30
parent 7e6e4ecfab
commit b74e4452dd
2 changed files with 38 additions and 0 deletions

View File

@ -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");
}
}

View File

@ -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)
);
}
}