-
Notifications
You must be signed in to change notification settings - Fork 295
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
Pagination broken for previous pages #443
Comments
The same issue happens when you go to CRUD edit page and come back, or CRUD add page and come back and also when you go to CRUD details page and click back to get to the list page. The previous button is disabled. |
Hi, I don't have time to open a PR at the moment, but this is my fixed version in case someone needs it or as a reference for the PR:
You can ignore the "exclude" parameter which is for my extended logic to exclude a series of results (I'm reusing the pagination for a selection component) |
Describe the bug
1st Issue:
Pagination component and hooks are working for the next page but not really working for previous page. The button is not enabled to go backwards. You can check that by adding enough CRUD items.
I fixed it by modifying the first useState() in the usePaginatedQuery.hook.ts hook. The first UseState() is setting cachedCursors to an empty[] when it finds the last cursor in the array. It’s not necessary. I changed it to only reset if it finds start cursor which it will never have.
Would like a better fix for the above. I believe the first useState() is not necessary.
2nd Issue:
Also when you are on page > 1 and then you click on Dashboard and when you return back to CRUD, it shows the page results you were on before with the pagination. HasNext works correctly so it shows the bottom for next page but you can’t go back to the previous page because cachedCursors array is empty and doesn’t have any of the previous page last cursors. I think Apollo Client is caching the last results and returning it on the page where we left off but it breaks the hasPrevious variable and there is no way to backwards. Especially if you are on the last page, both next and previous buttons are disabled and only way to get to page one, is to refresh the browser.
Need to make modifications to the usePaginatedQuery hook and fix to get the cachedCursors to work correctly with this cursor based pagination model.
Steps to reproduce
System Info
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: