Skip to content

Commit

Permalink
Prevent to set search params on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
mszula committed Nov 29, 2024
1 parent 4a1c8aa commit 3347db5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
).searchParams.get('algorithm');
if (!selectedAlgorithm) {
selectAlgorithm(algorithms[0][0]);
selectAlgorithm(algorithms[0][0], false);
} else {
const algo = algorithms
.flat()
Expand All @@ -55,7 +55,7 @@
);
if (algo) {
selectAlgorithm(algo);
selectAlgorithm(algo, false);
}
}
});
Expand Down Expand Up @@ -121,16 +121,21 @@
}
};
const selectAlgorithm = (algo: AlgorithmDefinition) => {
const selectAlgorithm = (
algo: AlgorithmDefinition,
setSearchParams = true
) => {
reset();
algorithm = { ...algo, instance: algo.function($arrayToSort) };
const url = new URL(window.location.toString());
url.searchParams.set(
'algorithm',
algo.name.toLowerCase().replace(/ /g, '-')
);
history.pushState({}, '', url);
if (setSearchParams) {
const url = new URL(window.location.toString());
url.searchParams.set(
'algorithm',
algo.name.toLowerCase().replace(/ /g, '-')
);
history.pushState({}, '', url);
}
};
</script>

Expand Down

0 comments on commit 3347db5

Please sign in to comment.