Skip to content

Instantly share code, notes, and snippets.

@karptonite
Last active February 27, 2018 20:35
Show Gist options
  • Save karptonite/9c557b4a965f20ce6e7db3bf29099856 to your computer and use it in GitHub Desktop.
Save karptonite/9c557b4a965f20ce6e7db3bf29099856 to your computer and use it in GitHub Desktop.
Pagination issue:

I have an interesting (to me) pagination related problem. I'm working on both the back end (a JSON API) and the front end (angular) of a comments system. Currently, the comments are page from oldest to newest, 20 per page, defaulting to the first page (oldest), with the API pages matching the pages we show to users.

We are switching to a front end with the following features: we show by default the x newest comments, with a "load previous" button to show y additional comments at a time. Additionally, you can deep link to a particular comment, which will mean showing x comments including x by default, with load y previous/next comments.

This is a private API for now, but may eventually become public. I'm trying to figure out how much of the new pagination behavior to handle in the API vs how much of it to handle in the client.

so, things I could put on the API or handle in the client include: passing perPage to the API or slicing up the data client side to handle the x / y per page requirements of the new system.

ordering issues; if I change nothing else, I will probably make it so that the API be default returns the newest perPage comments rather than the oldest.

I will also probably change from the current pagination system that passes page 1, 2, 3... to one that passes something like "beforeCommentid=53244234", etc, so that new comments coming in don't mess up the paging for users. I should add that comments are unthreaded, so this sort of limit makes some sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment