From 7f3e0f237b71a631c8aa3cd923bafc7245cd98a9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 13 Oct 2020 14:43:31 +0200 Subject: [PATCH] also do redirect after initial navigation --- src/domain/RootViewModel.js | 36 ++++++++++++++------------ src/domain/session/SessionViewModel.js | 4 +++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/domain/RootViewModel.js b/src/domain/RootViewModel.js index a5d0b0f2..6e3d86e9 100644 --- a/src/domain/RootViewModel.js +++ b/src/domain/RootViewModel.js @@ -38,7 +38,25 @@ export class RootViewModel extends ViewModel { async load() { this.track(this.navigation.observe("login").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 { // redirect depending on what sessions are already present 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) { if (sessionInfos.length === 0) { return this.urlRouter.urlForSegment("login"); diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index 2e1ec2ae..f0adb395 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -61,6 +61,10 @@ export class SessionViewModel extends ViewModel { } } + get id() { + return this._sessionContainer.sessionId; + } + start() { this._sessionStatusViewModel.start(); }