Skip to content

Commit

Permalink
Remove hash from URL after loading
Browse files Browse the repository at this point in the history
  • Loading branch information
cyderize committed Jun 14, 2024
1 parent bfde86b commit 413eeee
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,25 @@
return p;
}
let ignoreHashChange = false;
async function hashChange() {
if (window.location.hash.startsWith('#project=')) {
const hash = window.location.hash;
if (hash.length > 0) {
ignoreHashChange = true;
window.history.replaceState(
undefined,
undefined,
window.location.pathname + window.location.search,
);
ignoreHashChange = false;
}
if (ignoreHashChange) {
return;
}
if (hash.startsWith('#project=')) {
try {
const json = decodeURIComponent(
window.location.hash.substring(9),
);
const json = decodeURIComponent(hash.substring(9));
openProject(newSession(), {
...JSON.parse(json),
timestamp: Date.now(),
Expand All @@ -80,11 +93,9 @@
}
}
if (window.location.hash.startsWith('#code=')) {
if (hash.startsWith('#code=')) {
try {
const contents = decodeURIComponent(
window.location.hash.substring(6),
);
const contents = decodeURIComponent(hash.substring(6));
openProject(newSession(), {
files: [
{
Expand All @@ -101,11 +112,9 @@
}
}
if (window.location.hash.startsWith('#url=')) {
if (hash.startsWith('#url=')) {
try {
const url = decodeURIComponent(
window.location.hash.substring(5),
);
const url = decodeURIComponent(hash.substring(5));
openProject(newSession(), await loadFromUrl(url));
return;
} catch (e) {
Expand Down

0 comments on commit 413eeee

Please sign in to comment.