Fix restoring the last url at start

The last session url is now remembered for being restored at the beginning of the session. Thanks for the help of @bwindels
This commit is contained in:
Kaki In 2022-07-26 10:02:20 +02:00
parent bb5711db7e
commit adfecf0778
3 changed files with 14 additions and 13 deletions

View File

@ -27,7 +27,7 @@ export class URLRouter {
} }
_getLastSessionId() { _getLastSessionId() {
const navPath = this._urlAsNavPath(this._history.getLastUrl() || ""); const navPath = this._urlAsNavPath(this._history.getLastSessionUrl() || "");
const sessionId = navPath.get("session")?.value; const sessionId = navPath.get("session")?.value;
if (typeof sessionId === "string") { if (typeof sessionId === "string") {
return sessionId; return sessionId;
@ -84,7 +84,7 @@ export class URLRouter {
} }
tryRestoreLastUrl() { tryRestoreLastUrl() {
const lastNavPath = this._urlAsNavPath(this._history.getLastUrl() || ""); const lastNavPath = this._urlAsNavPath(this._history.getLastSessionUrl() || "");
if (lastNavPath.segments.length !== 0) { if (lastNavPath.segments.length !== 0) {
this._applyNavPathToNavigation(lastNavPath); this._applyNavPathToNavigation(lastNavPath);
return true; return true;

View File

@ -22,16 +22,16 @@ export function makeTxnId() {
} }
export function isTxnId(txnId) { export function isTxnId(txnId) {
return txnId.startsWith("t") && txnId.length === 15; return txnId.startsWith("t") && txnId.length === 15;
} }
export function tests() { export function tests() {
return { return {
"isTxnId succeeds on result of makeTxnId": assert => { "isTxnId succeeds on result of makeTxnId": assert => {
assert(isTxnId(makeTxnId())); assert(isTxnId(makeTxnId()));
}, },
"isTxnId fails on event id": assert => { "isTxnId fails on event id": assert => {
assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm")); assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm"));
}, },
} }
} }

View File

@ -65,6 +65,7 @@ export class History extends BaseObservableValue {
} }
onSubscribeFirst() { onSubscribeFirst() {
this._lastSessionHash = window.localStorage?.getItem("hydrogen_last_url_hash");
window.addEventListener('hashchange', this); window.addEventListener('hashchange', this);
} }
@ -76,7 +77,7 @@ export class History extends BaseObservableValue {
window.localStorage?.setItem("hydrogen_last_url_hash", hash); window.localStorage?.setItem("hydrogen_last_url_hash", hash);
} }
getLastUrl() { getLastSessionUrl() {
return window.localStorage?.getItem("hydrogen_last_url_hash"); return this._lastSessionHash;
} }
} }