also do redirect after initial navigation

This commit is contained in:
Bruno Windels 2020-10-13 14:43:31 +02:00
parent 1780f334ea
commit 7f3e0f237b
2 changed files with 23 additions and 17 deletions

View File

@ -38,7 +38,25 @@ export class RootViewModel extends ViewModel {
async load() { async load() {
this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation())); this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation()));
this.track(this.navigation.observe("session").subscribe(() => this._applyNavigation())); this.track(this.navigation.observe("session").subscribe(() => this._applyNavigation()));
if (!this._applyNavigation()) { this._applyNavigation();
}
async _applyNavigation() {
const isLogin = this.navigation.observe("login").get();
const sessionId = this.navigation.observe("session").get();
if (isLogin) {
if (this.activeSection !== "login") {
this._showLogin();
}
} else if (sessionId === true) {
if (this.activeSection !== "picker") {
this._showPicker();
}
} else if (sessionId) {
if (!this._sessionViewModel || this._sessionViewModel.id !== sessionId) {
this._showSessionLoader(sessionId);
}
} else {
try { try {
// redirect depending on what sessions are already present // redirect depending on what sessions are already present
const sessionInfos = await this._sessionInfoStorage.getAll(); const sessionInfos = await this._sessionInfoStorage.getAll();
@ -51,22 +69,6 @@ export class RootViewModel extends ViewModel {
} }
} }
_applyNavigation() {
const isLogin = this.navigation.observe("login").get();
const sessionId = this.navigation.observe("session").get();
if (isLogin) {
this._showLogin();
return true;
} else if (sessionId === true) {
this._showPicker();
return true;
} else if (sessionId) {
this._showSessionLoader(sessionId);
return true;
}
return false;
}
_urlForSessionInfos(sessionInfos) { _urlForSessionInfos(sessionInfos) {
if (sessionInfos.length === 0) { if (sessionInfos.length === 0) {
return this.urlRouter.urlForSegment("login"); return this.urlRouter.urlForSegment("login");

View File

@ -61,6 +61,10 @@ export class SessionViewModel extends ViewModel {
} }
} }
get id() {
return this._sessionContainer.sessionId;
}
start() { start() {
this._sessionStatusViewModel.start(); this._sessionStatusViewModel.start();
} }