From c3b56258a0f6c7f7ffeee366eb12ec28ac9740d8 Mon Sep 17 00:00:00 2001 From: Abdulbasid Guled Date: Thu, 1 Apr 2021 12:31:11 -0400 Subject: [PATCH] Fixed Search results request on every entered letter --- src/web/src/components/SearchProvider.tsx | 4 +++- src/web/src/components/SearchResults.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/web/src/components/SearchProvider.tsx b/src/web/src/components/SearchProvider.tsx index 02ac30af6d..abab412f50 100644 --- a/src/web/src/components/SearchProvider.tsx +++ b/src/web/src/components/SearchProvider.tsx @@ -7,6 +7,7 @@ type FilterProp = { export interface SearchContextInterface { text: string; + textParam: string; filter: FilterProp['filter']; showHelp: boolean; onTextChange: (value: string) => void; @@ -16,6 +17,7 @@ export interface SearchContextInterface { const SearchContext = createContext({ text: '', + textParam: '', filter: 'post', showHelp: true, onTextChange() { @@ -72,7 +74,7 @@ const SearchProvider = ({ children }: Props) => { return ( {children} diff --git a/src/web/src/components/SearchResults.tsx b/src/web/src/components/SearchResults.tsx index a79505ef11..d504fba857 100644 --- a/src/web/src/components/SearchResults.tsx +++ b/src/web/src/components/SearchResults.tsx @@ -51,13 +51,13 @@ const useStyles = makeStyles(() => ({ const SearchResults = () => { const classes = useStyles(); - const { text, filter } = useSearchValue(); + const { textParam, filter } = useSearchValue(); const prepareUrl = (index: number) => - `${telescopeUrl}/query?text=${encodeURIComponent(text)}&filter=${filter}&page=${index}`; + `${telescopeUrl}/query?text=${encodeURIComponent(textParam)}&filter=${filter}&page=${index}`; // We only bother doing the request if we have something to search for. - const shouldFetch = () => text.length > 0; + const shouldFetch = () => textParam.length > 0; const { data, size, setSize, error } = useSWRInfinite( (index) => (shouldFetch() ? prepareUrl(index) : null), async (u) => { @@ -92,7 +92,7 @@ const SearchResults = () => { ); } - if (text.length && loading) { + if (textParam.length && loading) { return (