diff options
| author | Fuwn <[email protected]> | 2023-12-14 16:55:40 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-14 16:55:40 -0800 |
| commit | dfd91282bd76a3070049f2a1af3cd2089fd8f69c (patch) | |
| tree | e0d19c30b130a819ad57793d36e8280ff1290cc6 /src/lib/Tools/tool.ts | |
| parent | feat(sequelspy): save options (diff) | |
| download | due.moe-dfd91282bd76a3070049f2a1af3cd2089fd8f69c.tar.xz due.moe-dfd91282bd76a3070049f2a1af3cd2089fd8f69c.zip | |
fix(tools): better clear parameters
Diffstat (limited to 'src/lib/Tools/tool.ts')
| -rw-r--r-- | src/lib/Tools/tool.ts | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/lib/Tools/tool.ts b/src/lib/Tools/tool.ts index fc50a715..cf24eb8c 100644 --- a/src/lib/Tools/tool.ts +++ b/src/lib/Tools/tool.ts @@ -1,16 +1,21 @@ import { browser } from '$app/environment'; import { page } from '$app/stores'; +import { get } from 'svelte/store'; export const clearAllParameters = (saved: string[] = []) => { - if (browser) - page.subscribe((value) => { - value.url.searchParams.forEach((_, key) => { - if (!saved.includes(key) && key !== 'tool') { - value.url.searchParams.delete(key); - } - }); - history.replaceState(null, '', `?${value.url.searchParams.toString()}`); + if (browser) { + const parameters = new URLSearchParams(); + + if (get(page).url.searchParams.has('tool')) + parameters.set('tool', get(page).url.searchParams.get('tool') || ''); + + saved.forEach((key) => { + if (get(page).url.searchParams.has(key)) { + parameters.set(key, get(page).url.searchParams.get(key) || ''); + } }); + history.replaceState(null, '', `${get(page).url.pathname}?${parameters}`); + } }; export const parseOrDefault = <T = string | number>( |