forked from mystiq/hydrogen-web
also do redirect after initial navigation
This commit is contained in:
parent
1780f334ea
commit
7f3e0f237b
2 changed files with 23 additions and 17 deletions
|
@ -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");
|
||||
|
|
|
@ -61,6 +61,10 @@ export class SessionViewModel extends ViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this._sessionContainer.sessionId;
|
||||
}
|
||||
|
||||
start() {
|
||||
this._sessionStatusViewModel.start();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue