Skip to content

Commit

Permalink
Merge pull request #1376 from Shelf-nu/1372-bug-search-not-working-if…
Browse files Browse the repository at this point in the history
…-pagination-1

fix: making sure page param is cleared when a new search query is made
  • Loading branch information
DonKoko authored Oct 28, 2024
2 parents e23af94 + 32c2cfe commit 77569fc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/components/list/filters/search-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@ export const SearchForm = ({ className }: { className?: string }) => {

const label = searchFieldLabel ? searchFieldLabel : `Search by ${singular}`;

/**
* Clears the search parameter and page parameter from the URL
* to ensure we start from the first page of results
*/
function clearSearch() {
setSearchParams((prev) => {
prev.delete("s");

prev.delete("page"); // Reset page when clearing search
return prev;
});
if (searchInputRef.current) {
searchInputRef.current.value = "";
}
}

/**
* Handles search input changes with debouncing
* Resets page to 1 whenever search query changes
*/
const debouncedHandleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
Expand All @@ -41,6 +48,7 @@ export const SearchForm = ({ className }: { className?: string }) => {
} else {
setSearchParams((prev) => {
prev.set("s", searchQuery);
prev.delete("page"); // Reset to page 1 when search query changes
return prev;
});
}
Expand Down

0 comments on commit 77569fc

Please sign in to comment.