mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 11:36:24 +01:00
restore last url if not providing a specific one on startup
This commit is contained in:
parent
19e774ce01
commit
7c2fc516bb
@ -35,13 +35,13 @@ export class RootViewModel extends ViewModel {
|
||||
this._sessionViewModel = null;
|
||||
}
|
||||
|
||||
async load() {
|
||||
async load(lastUrlHash) {
|
||||
this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation()));
|
||||
this.track(this.navigation.observe("session").subscribe(() => this._applyNavigation()));
|
||||
this._applyNavigation();
|
||||
this._applyNavigation(lastUrlHash);
|
||||
}
|
||||
|
||||
async _applyNavigation() {
|
||||
async _applyNavigation(restoreHashIfAtDefault) {
|
||||
const isLogin = this.navigation.observe("login").get();
|
||||
const sessionId = this.navigation.observe("session").get();
|
||||
if (isLogin) {
|
||||
@ -58,9 +58,12 @@ export class RootViewModel extends ViewModel {
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
// redirect depending on what sessions are already present
|
||||
const sessionInfos = await this._sessionInfoStorage.getAll();
|
||||
const url = this._urlForSessionInfos(sessionInfos);
|
||||
let url = restoreHashIfAtDefault;
|
||||
if (!url) {
|
||||
// redirect depending on what sessions are already present
|
||||
const sessionInfos = await this._sessionInfoStorage.getAll();
|
||||
url = this._urlForSessionInfos(sessionInfos);
|
||||
}
|
||||
this.urlRouter.history.replaceUrl(url);
|
||||
this.urlRouter.applyUrl(url);
|
||||
} catch (err) {
|
||||
|
@ -142,11 +142,18 @@ export async function main(container, paths, legacyExtras) {
|
||||
navigation
|
||||
});
|
||||
window.__brawlViewModel = vm;
|
||||
await vm.load();
|
||||
const lastUrlHash = window.localStorage?.getItem("hydrogen_last_url_hash");
|
||||
await vm.load(lastUrlHash);
|
||||
// TODO: replace with platform.createAndMountRootView(vm, container);
|
||||
const view = new RootView(vm);
|
||||
container.appendChild(view.mount());
|
||||
window.addEventListener("beforeunload", storeUrlHashOnClose);
|
||||
} catch(err) {
|
||||
console.error(`${err.message}:\n${err.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
function storeUrlHashOnClose() {
|
||||
window.localStorage?.setItem("hydrogen_last_url_hash", document.location.hash);
|
||||
window.removeEventListener("beforeunload", storeUrlHashOnClose);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user