1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-26 10:50:29 +02:00

fix(web): remove query parameter when clearing search (#8817)

fix: remove query parameter when clearing search
This commit is contained in:
martin 2024-04-15 20:20:32 +02:00 committed by GitHub
parent f959f2de85
commit 7ce1662b05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View File

@ -1,3 +1,12 @@
import { goto } from '$app/navigation';
export const isExternalUrl = (url: string): boolean => { export const isExternalUrl = (url: string): boolean => {
return new URL(url, window.location.href).origin !== window.location.origin; return new URL(url, window.location.href).origin !== window.location.origin;
}; };
export const clearQueryParam = async (queryParam: string, url: URL) => {
if (url.searchParams.has(queryParam)) {
url.searchParams.delete(queryParam);
await goto(url);
}
};

View File

@ -40,6 +40,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import type { PageData } from './$types'; import type { PageData } from './$types';
import { locale } from '$lib/stores/preferences.store'; import { locale } from '$lib/stores/preferences.store';
import { clearQueryParam } from '$lib/utils/navigation';
export let data: PageData; export let data: PageData;
@ -279,10 +280,7 @@
const handleSearchPeople = async (force: boolean) => { const handleSearchPeople = async (force: boolean) => {
if (searchName === '') { if (searchName === '') {
if ($page.url.searchParams.has(QueryParameter.SEARCHED_PEOPLE)) { await clearQueryParam(QueryParameter.SEARCHED_PEOPLE, $page.url);
$page.url.searchParams.delete(QueryParameter.SEARCHED_PEOPLE);
await goto($page.url);
}
return; return;
} }
if (!force && people.length < maximumLengthSearchPeople && searchName.startsWith(searchWord)) { if (!force && people.length < maximumLengthSearchPeople && searchName.startsWith(searchWord)) {
@ -393,6 +391,11 @@
handleError(error, 'Unable to save name'); handleError(error, 'Unable to save name');
} }
}; };
const onResetSearchBar = async () => {
searchedPeople = [];
await clearQueryParam(QueryParameter.SEARCHED_PEOPLE, $page.url);
};
</script> </script>
<svelte:window bind:innerHeight use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: handleCloseClick }} /> <svelte:window bind:innerHeight use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: handleCloseClick }} />
@ -421,9 +424,7 @@
bind:name={searchName} bind:name={searchName}
isSearching={isSearchingPeople} isSearching={isSearchingPeople}
placeholder="Search people" placeholder="Search people"
on:reset={() => { on:reset={onResetSearchBar}
searchedPeople = [];
}}
on:search={({ detail }) => handleSearch(detail.force ?? false)} on:search={({ detail }) => handleSearch(detail.force ?? false)}
/> />
</div> </div>