Fix using permalink on new page

This commit is contained in:
Austen Adler 2023-04-30 15:52:02 -04:00
parent 0a44b8363d
commit e8fc755083

View File

@ -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();
}
}
</script>