-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: resets pagination when search term changes in drawer list #5599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.x
Are you sure you want to change the base?
Conversation
@jacobsfletch I think you'd be best to help review this with me. When you have some time could we look at this PR together? Thanks! |
@@ -198,6 +198,10 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({ | |||
setPreference(preferenceKey, newPreferences, true) | |||
}, [sort, limit, setPreference, preferenceKey]) | |||
|
|||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, this isn't quite right. Instead of adding a new useEffect
, you should be able to tie into the methods that the SearchFilter
component exposed via props. The drawer sets modifySearchParams
to false
, which is where the page reset is being bypassed. Basically just need to thread the page reset back into the search before it's set, instead of after its set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes:
- Consolidate all 5
useState
s in theListDrawer
component - Replace them with a new
params
state, and completely remove theuseEffect
- This would mean that the filter options injected into the
where
query, and the conditions formatted from thesearch
string, need to become methods that properly setparams
- This is exactly what a reducer is for, might as well use it. We can create reducer actions like
setSearc
h which properly formatsconditions
and resetspage
, andsetWhere
,setParams
to blindy set any of them, etc. - This all makes it so that the
usePayloadAPI
hook (which makes an API request) is only fired once no matter what params change and when
Description
fix: resets pagination to page 1 every time the search term changes
Type of change
Checklist: