Skip to content

Commit

Permalink
SearchPage: Enhance and improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 committed May 17, 2024
1 parent 33314f7 commit 0178823
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions client/pages/search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ export const SearchPage = () => {
const [searchResults, setSearchResults] = usePubSub(searchResultsPubSub);
const [urlsDescriptions] = usePubSub(urlsDescriptionsPubSub);
const [isLoading, setIsLoading] = useState(false);
const isUserSubscribed = useSubscriptionStatus();
const { incrementQueryCount } = useQueryCount();

const location = useLocation();

const clearResponses = () => {
const clearResponses = useCallback(() => {
setSearchResults([]);
setResponse("");
};
}, [setSearchResults, setResponse]);

useEffect(() => {
Engine.prepareTextGeneration();
Expand All @@ -70,11 +69,18 @@ export const SearchPage = () => {
const performSearch = useCallback(async () => {
if (query.length) {
setIsLoading(true);
const results = await search(query);
setSearchResults(results);
incrementQueryCount(); // Increment query count when a search result is received
try {
const results = await search(query);
setSearchResults(results);

// Increment query count when a search result is received
incrementQueryCount();
} catch (error) {
console.error("Error performing search:", error);
} finally {
setIsLoading(false);
}
}
setIsLoading(false);
}, [query, setSearchResults, incrementQueryCount]);

useEffect(() => {
Expand Down

0 comments on commit 0178823

Please sign in to comment.