forked from mystiq/hydrogen-web
implement root view as template view
This commit is contained in:
parent
0f8f558889
commit
1289f065d6
1 changed files with 20 additions and 50 deletions
|
@ -20,58 +20,28 @@ import {SessionLoadView} from "./login/SessionLoadView.js";
|
||||||
import {SessionPickerView} from "./login/SessionPickerView.js";
|
import {SessionPickerView} from "./login/SessionPickerView.js";
|
||||||
import {TemplateView} from "./general/TemplateView.js";
|
import {TemplateView} from "./general/TemplateView.js";
|
||||||
import {StaticView} from "./general/StaticView.js";
|
import {StaticView} from "./general/StaticView.js";
|
||||||
import {SwitchView} from "./general/SwitchView.js";
|
|
||||||
|
|
||||||
export class RootView {
|
export class RootView extends TemplateView {
|
||||||
constructor(vm) {
|
render(t, vm) {
|
||||||
this._vm = vm;
|
return t.mapView(vm => vm.activeSection, activeSection => {
|
||||||
this._switcher = null;
|
switch (activeSection) {
|
||||||
this._root = null;
|
case "error":
|
||||||
this._onViewModelChange = this._onViewModelChange.bind(this);
|
return new StatusView({header: "Something went wrong", message: vm.errorText});
|
||||||
|
case "session":
|
||||||
|
return new SessionView(vm.sessionViewModel);
|
||||||
|
case "login":
|
||||||
|
return new LoginView(vm.loginViewModel);
|
||||||
|
case "picker":
|
||||||
|
return new SessionPickerView(vm.sessionPickerViewModel);
|
||||||
|
case "redirecting":
|
||||||
|
return new StaticView(t => t.p("Redirecting..."));
|
||||||
|
case "loading":
|
||||||
|
return new SessionLoadView(vm.sessionLoadViewModel);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown section: ${vm.activeSection}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_getView() {
|
|
||||||
switch (this._vm.activeSection) {
|
|
||||||
case "error":
|
|
||||||
return new StatusView({header: "Something went wrong", message: this._vm.errorText});
|
|
||||||
case "session":
|
|
||||||
return new SessionView(this._vm.sessionViewModel);
|
|
||||||
case "login":
|
|
||||||
return new LoginView(this._vm.loginViewModel);
|
|
||||||
case "picker":
|
|
||||||
return new SessionPickerView(this._vm.sessionPickerViewModel);
|
|
||||||
case "redirecting":
|
|
||||||
return new StaticView(t => t.p("Redirecting..."));
|
|
||||||
case "loading":
|
|
||||||
return new SessionLoadView(this._vm.sessionLoadViewModel);
|
|
||||||
default:
|
|
||||||
throw new Error(`Unknown section: ${this._vm.activeSection}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_onViewModelChange(prop) {
|
|
||||||
if (prop === "activeSection") {
|
|
||||||
this._switcher.switch(this._getView());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mount() {
|
|
||||||
this._switcher = new SwitchView(this._getView());
|
|
||||||
this._root = this._switcher.mount();
|
|
||||||
this._vm.on("change", this._onViewModelChange);
|
|
||||||
return this._root;
|
|
||||||
}
|
|
||||||
|
|
||||||
unmount() {
|
|
||||||
this._vm.off("change", this._onViewModelChange);
|
|
||||||
this._switcher.unmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
root() {
|
|
||||||
return this._root;
|
|
||||||
}
|
|
||||||
|
|
||||||
update() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatusView extends TemplateView {
|
class StatusView extends TemplateView {
|
||||||
|
|
Loading…
Reference in a new issue