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 | |
| 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')
| -rw-r--r-- | src/lib/Tools/CharacterBirthdays.svelte | 3 | ||||
| -rw-r--r-- | src/lib/Tools/SequelSpy.svelte | 2 | ||||
| -rw-r--r-- | src/lib/Tools/Wrapped.svelte | 1 | ||||
| -rw-r--r-- | src/lib/Tools/tool.ts | 21 |
4 files changed, 18 insertions, 9 deletions
diff --git a/src/lib/Tools/CharacterBirthdays.svelte b/src/lib/Tools/CharacterBirthdays.svelte index 936db0c3..3a8abaed 100644 --- a/src/lib/Tools/CharacterBirthdays.svelte +++ b/src/lib/Tools/CharacterBirthdays.svelte @@ -4,6 +4,7 @@ import { ACDBBirthdays, type ACDBBirthday } from '$lib/Birthday/ACDB'; import { aniSearchBirthdays, type aniSearchBirthday } from '$lib/Birthday/aniSearch'; import Error from '$lib/Error.svelte'; + import { onMount } from 'svelte'; import { clearAllParameters, parseOrDefault } from './tool'; interface Birthday { @@ -36,6 +37,8 @@ } } + onMount(() => clearAllParameters(['month', 'day'])); + const normalizeName = (name: string): string => name.toLowerCase().split(' ').sort().join(' '); const combineBirthdaySources = ( diff --git a/src/lib/Tools/SequelSpy.svelte b/src/lib/Tools/SequelSpy.svelte index 5ef94c1f..56f40956 100644 --- a/src/lib/Tools/SequelSpy.svelte +++ b/src/lib/Tools/SequelSpy.svelte @@ -40,7 +40,7 @@ } } - onMount(clearAllParameters); + onMount(() => clearAllParameters(['year', 'season'])); const prequelAiringTime = (prequel: MediaPrequel) => airingTime(prequel as unknown as Media); </script> diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte index 9ee776f9..e18f2359 100644 --- a/src/lib/Tools/Wrapped.svelte +++ b/src/lib/Tools/Wrapped.svelte @@ -118,6 +118,7 @@ 'forceDark', 'highestRatedCount' ]); + if (browser) { transparency = $page.url.searchParams.get('transparency') === 'true'; lightTheme = $page.url.searchParams.get('lightTheme') === 'true'; 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>( |