From e8fc755083f7ffe888e4ea1848013958497a4ee9 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 30 Apr 2023 15:52:02 -0400 Subject: [PATCH] Fix using permalink on new page --- web-frontend/src/routes/+page.svelte | 41 ++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/web-frontend/src/routes/+page.svelte b/web-frontend/src/routes/+page.svelte index c932909..f5a87f7 100644 --- a/web-frontend/src/routes/+page.svelte +++ b/web-frontend/src/routes/+page.svelte @@ -89,7 +89,12 @@ .then(tick) .then(async () => { // Initialize the actual app - updateAddr(wasm.call.EncodedAddress.from_coordinate(coordinateInputValue), true); + if (lastHash) { + addrInputValue; + updateAddr(wasm.call.EncodedAddress.from_address(addrInputValue), true); + } else { + updateAddr(wasm.call.EncodedAddress.from_coordinate(coordinateInputValue), true); + } }) .catch((err) => { console.log('Erroring'); @@ -168,6 +173,29 @@ } }; + const checkHash = () => { + if ($url && $url.hash) { + let hash = decodeURI($url.hash.substr(1)) + .replaceAll(/-|\+|\s+/g, ' ') + .trim(); + + let updatedFromHash = false; + if (hash !== lastHash) { + updatedFromHash = true; + addrInputValue = hash; + if (lastHash) { + // If this is the first time we call this function, don't update the address + // Because wasm is not yet defined + addressInput(); + } + } + + lastHash = hash; + + return updatedFromHash; + } + }; + let mapIsVisible = false; $: { @@ -177,16 +205,7 @@ let lastHash; $: { if ($url && $url.hash) { - let hash = decodeURI($url.hash.substr(1)) - .replaceAll(/-|\+|\s+/g, ' ') - .trim(); - - if (hash !== lastHash) { - addrInputValue = hash; - addressInput(); - } - - lastHash = hash; + checkHash(); } }