Skip to content
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

Simplify pagination #17

Open
luisherranz opened this issue May 4, 2020 · 0 comments
Open

Simplify pagination #17

luisherranz opened this issue May 4, 2020 · 0 comments
Labels
good first issue Good for newcomers

Comments

@luisherranz
Copy link
Collaborator

luisherranz commented May 4, 2020

We don't have to use libraries.source.parse and libraries.source.stringify for next and previous page anymore, so we can simplify this code: https://github.com/chakra-ui/frontity-chakra-ui-theme/blob/master/packages/frontity-chakra-theme/src/components/archive/pagination.js#L63-L78

const { totalPages } = state.source.get(state.router.link);
const { path, page, query } = libraries.source.parse(state.router.link);

const isThereNextPage = page > 1;
const isTherePreviousPage = page < totalPages;

const nextPageLink = libraries.source.stringify({
  path,
  page: page + 1,
  query,
});

const prevPageLink = libraries.source.stringify({
  path,
  page: page - 1,
  query,
});

And just use the next and previous we get from data:

const { totalPages, route, page, next, previous } = state.source.get(
  state.router.link
);

Please note that path has been renamed and is now route.

Docs: https://docs.frontity.org/api-reference-1/wordpress-source#state

@luisherranz luisherranz added the good first issue Good for newcomers label Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant