2019-06-16 14:22:02 +05:30
|
|
|
import ListView from "../general/ListView.js";
|
2019-02-28 03:20:08 +05:30
|
|
|
import RoomTile from "./RoomTile.js";
|
2019-06-16 14:22:02 +05:30
|
|
|
import RoomView from "./room/RoomView.js";
|
|
|
|
import SwitchView from "../general/SwitchView.js";
|
2019-06-15 21:20:15 +05:30
|
|
|
import RoomPlaceholderView from "./RoomPlaceholderView.js";
|
2019-06-16 14:22:02 +05:30
|
|
|
import SyncStatusBar from "./SyncStatusBar.js";
|
|
|
|
import {tag} from "../general/html.js";
|
2019-02-28 03:20:08 +05:30
|
|
|
|
|
|
|
export default class SessionView {
|
|
|
|
constructor(viewModel) {
|
|
|
|
this._viewModel = viewModel;
|
2019-06-15 21:20:15 +05:30
|
|
|
this._middleSwitcher = null;
|
2019-02-28 03:20:08 +05:30
|
|
|
this._roomList = null;
|
|
|
|
this._currentRoom = null;
|
|
|
|
this._root = null;
|
|
|
|
this._onViewModelChange = this._onViewModelChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
root() {
|
|
|
|
return this._root;
|
|
|
|
}
|
|
|
|
|
|
|
|
mount() {
|
|
|
|
this._viewModel.on("change", this._onViewModelChange);
|
2019-06-16 14:22:02 +05:30
|
|
|
this._syncStatusBar = new SyncStatusBar(this._viewModel.syncStatusViewModel);
|
2019-02-28 03:20:08 +05:30
|
|
|
this._roomList = new ListView(
|
|
|
|
{
|
|
|
|
list: this._viewModel.roomList,
|
2019-02-28 03:51:00 +05:30
|
|
|
onItemClick: (roomTile, event) => roomTile.clicked(event)
|
2019-02-28 03:20:08 +05:30
|
|
|
},
|
|
|
|
(room) => new RoomTile(room)
|
|
|
|
);
|
2019-06-15 21:20:15 +05:30
|
|
|
this._middleSwitcher = new SwitchView(new RoomPlaceholderView());
|
2019-06-16 14:22:02 +05:30
|
|
|
|
|
|
|
this._root = tag.div({className: "SessionView"}, [
|
|
|
|
this._syncStatusBar.mount(),
|
|
|
|
tag.div({className: "main"}, [
|
|
|
|
this._roomList.mount(),
|
|
|
|
this._middleSwitcher.mount()
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
|
2019-02-28 03:20:08 +05:30
|
|
|
return this._root;
|
|
|
|
}
|
|
|
|
|
|
|
|
unmount() {
|
|
|
|
this._roomList.unmount();
|
2019-06-15 21:20:15 +05:30
|
|
|
this._middleSwitcher.unmount();
|
2019-02-28 03:20:08 +05:30
|
|
|
this._viewModel.off("change", this._onViewModelChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onViewModelChange(prop) {
|
|
|
|
if (prop === "currentRoom") {
|
2019-06-15 21:20:15 +05:30
|
|
|
this._middleSwitcher.switch(new RoomView(this._viewModel.currentRoom));
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// changing viewModel not supported for now
|
|
|
|
update() {}
|
|
|
|
}
|