Skip to content

Commit

Permalink
fixed entity search with debounce implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn committed Feb 20, 2024
1 parent f0befa8 commit 5aa0026
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/graph/search_bar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,35 @@ const SearchBar: FC<SearchBarProps> = ({ className, onSearchAddress }) => {
} else {
setEntitySearchResults([]);
}
}, []);
}, [query]);

const searchQuery = useCallback((query: string) => {
console.log
if (!query) {
setEntitySearchResults([]);
return;
}

fetchLabels(query);
}, []);
}, [query]);

useEffect(() => {
debounce(
// Debounce function to prevent too many requests
const debounceFunc = debounce(
() => {
searchQuery(query);
},
300,
{ trailing: true },
);
{ maxWait: 1000 }
)

// Call the debounce function
debounceFunc();

return () => {
// Cancel the debounce function if the component unmounts or the query changes
debounceFunc.cancel();
}
}, [query]);

// Combine uniqueSearchHistory and entitySearchResults into a single list of search results
Expand Down

0 comments on commit 5aa0026

Please sign in to comment.