Skip to content

Commit

Permalink
fix(web): grants pagination reset page count (#17665)
Browse files Browse the repository at this point in the history
fix: init
  • Loading branch information
thorkellmani authored Jan 29, 2025
1 parent b4c8d9e commit 4ab25e3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions apps/web/screens/Grants/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
'status',
parseAsStringLiteral(Availability),
)
const [searchString, setSearchString] = useState<string | null>()

const [initialRender, setInitialRender] = useState<boolean>(true)

Expand Down Expand Up @@ -116,7 +117,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
lang: locale,
organizations: organizations ? [...organizations] : null,
page,
search: query,
search: searchString,
size: PAGE_SIZE,
types: types ? [...types] : null,
status: status
Expand Down Expand Up @@ -145,18 +146,24 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
organizations,
page,
status,
query,
searchString,
types,
initialRender,
])

useEffect(() => {
fetchGrants()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [categories, locale, organizations, page, searchString, types, status])

//SEARCH STATE UPDATES
const debouncedSearchUpdate = useMemo(() => {
return debounce(() => {
fetchGrants()
setSearchString(query)
setPage(null)
}, debounceTime.search)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [categories, locale, organizations, page, query, types, status])
}, [query])

useEffect(() => {
debouncedSearchUpdate()
Expand All @@ -182,8 +189,9 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
]

const onResetFilter = () => {
setPage(1)
setPage(null)
setQuery(null)
setSearchString(null)
setCategories(null)
setTypes(null)
setOrganizations(null)
Expand Down Expand Up @@ -229,6 +237,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
break
}
}
setPage(null)
}

return (
Expand Down

0 comments on commit 4ab25e3

Please sign in to comment.