Skip to content

Commit

Permalink
Cleanup SearchBar
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw-zakrzewski committed Oct 23, 2024
1 parent 005cda7 commit 9dcf40e
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions verification/curator-service/ui/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ export default function SearchBar({
const [isUserTyping, setIsUserTyping] = useState<boolean>(false);
const [isDataGuideOpen, setIsDataGuideOpen] = useState<boolean>(false);
const [searchInput, setSearchInput] = useState<string>(
location.search.includes('?q=')
? location.search.split('?q=')[1]
: location.search?.includes('&q=')
? location.search.split('&q=')[1]
: '',
new URLSearchParams(location.search).get('q') || '',
);
const [modalAlert, setModalAlert] = useState<boolean>(false);
const guideButtonRef = React.useRef<HTMLButtonElement>(null);
Expand All @@ -105,14 +101,13 @@ export default function SearchBar({
}, [filtersBreadcrumb]);

useEffect(() => {
const q = (new URLSearchParams(location.search)).get('q') || '';
const q = new URLSearchParams(location.search).get('q') || '';
if (q !== searchInput) setSearchInput(q);
}, [location.search]);

// Set search query debounce to 1000ms
const debouncedSearch = useDebounce(searchInput, 2000);


const handleNavigating = (q: string) => {
const searchParams = new URLSearchParams(location.search);
q !== '' ? searchParams.set('q', q) : searchParams.delete('q');
Expand All @@ -121,7 +116,7 @@ export default function SearchBar({
pathname: '/cases',
search: searchParams.toString(),
});
}
};

// Apply filter parameters after delay
useEffect(() => {
Expand Down Expand Up @@ -180,7 +175,7 @@ export default function SearchBar({
if (searchError) {
return 'Incorrect entry. ":" characters have been removed. Please use filters instead.';
} else {
const quoteCount = decodeURIComponent(searchInput).split('"').length - 1;
const quoteCount = searchInput.split('"').length - 1;
if (quoteCount % 2 !== 0) {
return 'Incorrect entry. Please make sure you have an even number of quotes.';
}
Expand Down

0 comments on commit 9dcf40e

Please sign in to comment.