From 5e04403c5e3f92b68eb48eda3e7daaf17d24ec11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Zakrzewski?= Date: Wed, 23 Oct 2024 13:34:38 +0200 Subject: [PATCH] Update SearchBar.tsx --- .../ui/src/components/SearchBar.tsx | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/verification/curator-service/ui/src/components/SearchBar.tsx b/verification/curator-service/ui/src/components/SearchBar.tsx index dac2b9f9b..a58fdf8d5 100644 --- a/verification/curator-service/ui/src/components/SearchBar.tsx +++ b/verification/curator-service/ui/src/components/SearchBar.tsx @@ -122,42 +122,16 @@ export default function SearchBar({ const handleNavigating = (q: string) => { - const encodedQ = encodeURIComponent(q); - if (encodedQ === '') { - if (location.search.includes('?q=')) { - navigate({ - pathname: '/cases', - search: '', - }); - } else if(location.search.includes('&q=')) { - navigate({ - pathname: '/cases', - search: location.search.split('&q=')[0], - }); - } else { - navigate({ - pathname: '/cases', - search: location.search, - }); - } + const searchParams = new URLSearchParams(location.search); + if (q !== '') { + searchParams.set('q', q); } else { - if (location.search.includes('?q=') || location.search === '') { - navigate({ - pathname: '/cases', - search: `?q=${encodedQ}`, - }); - } else if(location.search.includes('&q=')) { - navigate({ - pathname: '/cases', - search: `${location.search.split('&q=')[0]}&q=${encodedQ}`, - }); - } else { - navigate({ - pathname: '/cases', - search: `${location.search}&q=${encodedQ}`, - }); - } + searchParams.delete('q'); } + navigate({ + pathname: '/cases', + search: searchParams.toString(), + }); } // Apply filter parameters after delay