Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Fix Page control index when total number of pages changes #748

Closed
wants to merge 4 commits into from

Conversation

Coteh
Copy link
Collaborator

@Coteh Coteh commented May 7, 2020

Fixes #658.

Current Behavior ( Optional for new feature )

Description

If page is changed to a page whose number is greater than total amount of pages (can happen when number of pages changes in between page changes), then the current page will still be set to that page instead of falling back to the new last page.

Screenshots

See #658

New Behavior

Description

Now when the total number of pages changes after a page change, the page selected will fall back to the last page.

Screenshots

result

Note

This solution uses getDerivedStateFromProps, which is not a recommended approach to handling derived state. An alternative solution would be letting the parent of PageControl component control the current index, but I think this will introduce unneeded complexity. Additionally, the logic within the getDerivedStateFromProps method will not override any local changes to the currentPageIdx value if it's less than or equal to the total number of pages, which is expected behaviour.

@Coteh Coteh changed the title Page control Fix Page control index when total number of pages changes May 7, 2020
@Coteh Coteh marked this pull request as draft May 7, 2020 23:10
@magicoder10
Copy link
Member

@Coteh This is not a bug. It' the limitation offset based pagination. I was working on a design proposal and prototype to address those. The true solution is using cursor based pagination.

@Coteh
Copy link
Collaborator Author

Coteh commented May 7, 2020

Whoops my bad I'll close.

@Coteh Coteh closed this May 7, 2020
@magicoder10 magicoder10 deleted the page-control branch June 7, 2020 07:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Handle edge cases for page control
2 participants