Skip to content

Commit

Permalink
Prevent double-entering on the same search terms
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiramTadepalli committed Jan 4, 2025
1 parent 33909cf commit 1afbdea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/search/SearchBar/searchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,32 @@ const SearchBar = ({

//change all values
function updateValue(newValue: SearchQuery[]) {
console.log('inside updateValue');
setValue(newValue);
onSelect_internal(newValue); // clicking enter to select a autocomplete suggestion triggers a new search (it also 'Enters' for the searchbar)
}

//update parent and queries
function onSelect_internal(newValue: SearchQuery[]) {
if (
router.query.searchTerms ==
newValue.map((el) => searchQueryLabel(el)).join(',')
)
// do not initiate a new search when the searchTerms haven't changed
return;
setErrorTooltip(!newValue.length); //Check if tooltip needs to be displayed
if (newValue.length && typeof setResultsLoading !== 'undefined') {
setResultsLoading();
}
console.log(newValue);
if (typeof onSelect !== 'undefined') {
console.log('inside onselect');
onSelect(newValue);
}
if (newValue.length && manageQuery === 'onSelect') {
console.log('inside updatequeries');
updateQueries(newValue);
}
}

function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
if (event.key === 'Enter' && inputValue === '') {
console.log('handleKeyDown');
event.preventDefault();
event.stopPropagation();
onSelect_internal(value);
Expand Down Expand Up @@ -264,7 +265,6 @@ const SearchBar = ({
}}
//for handling spaces, when options are already loaded
onInput={(event) => {
console.log('onInput');
const value = (event.target as HTMLInputElement).value;
// if the last character in the new string is a space, check for autocomplete
if (
Expand Down

0 comments on commit 1afbdea

Please sign in to comment.