Paginate is used for querying & paginating API responses. Paginate will
handle fetching new pages of data, and caches already fetched data.
TODO: Eventually:
Get an initial Pagination & Fetch Commands from a Config, list of Filters,
& Page Number.
The Config type is used to build a Fetch Request, given the Paginated's
Request Data, a Page Number, & the Items per Page.
The result type of a Paginated Fetch Request. At the minimum, your API needs to return the items & a total count of all items.
If any additional data is returned that you would like to have access to, you
can decode it to the extraData field and use getResponseData to pull it
out of a Paginated.
Make a Config from a function that takes a list of Parameters & a Page Number.
Get the current list of items.
Get the number of items to show per page.
Get the total number of pages.
Get the total item count.
Return the current page's fetch request's error if it has one.
Return the Extra Request Data for the current Paginated.
Return any Extra Response Data for the current Paginated.
Return the raw WebData for the current page.
Generate sections of pages to show for a Pager. Depending on the current page & total number of pages, the sections may either be a single section, a beginning & end section, or a beginning, middle, & end section.
Each section's page is a tuple of (pageNumber, isCurrentPage).
The sections are defined by the initial arguments, the first is the number of pages to show at the end sections, while the second is the number of pages to show around the current page if it is in the middle section.
Some example of Pagers generated with 2 end & middle pages, with the current
page marked by *:
*1*|2|3|4|5|6
*1*|2|3|4|5|...|49|50
1|2|3|4|*5*|...|49|50
1|2|...|4|5|*6*|7|8|...|49|50
1|2|...|9|10|*11*|12|13|...|49|50
1|2|...|*46*|47|48|49|50No split is made if there are not enough pages to show a middle section. When at an end section, enough pages are shown that there must be something hidden before splitting off the middle section.
Render a split Pager with the standard Bootstrap4 classes.
It takes a function that takes a page number & generates attributes for an
item's a element, the number of pages to show at the ends of the pagination,
the number of middle pages to show in the middles of the pagination, and a
pagination.
It will split out a list of li elements for each page that should be shown,
with disabled dots(...) between each section. A list is returned so that you
can add previous/next buttons if you want them.
See the docs for getPagerSections to see how the splitting works.
Are there page's before the current one?
Move to the next page.
TODO: re-implement as call to jumpTo?
Move to the previous page.
TODO: re-implement as call to jumpTo?
Move to a specific page.
Replace the current Extra Request Data, jumping to page 1 & performing new fetch requests. Does nothing if the Data is equal to existing Data.
Similar to the updateData function, but this will also reset the
ResponseData.
Which you should pick depends on how the new request data affects your response
data. E.g., if the slug of the pagination container changes, you should reset
the response data as well, but if you're only changing the sorting order of the
results, you can just use the updateData function.
Update the items per page, jumping to page 1 & performing new fetch requests. Does nothing if the new value is the same as the current items per page.
Wrap an Http Response for a Page, to be handled in the update function.
Update the Paginated Model on Fetch Completion.
If the Page Number of the Returned Model is Different than the Given Model, We Were On a Page That Didn't Exist, So We Changed to the Last Page.
You Should Handle this Special Case in your Update Function, so that You can Modify the Page URL.
The
Paginatedtype is responsible for storing the fetched items, current page number, total count, and additional data to pass to the fetch command..The
atype refers to the data that is paginated,brefers to any additional data you need to make the API request, andcis any additional data you want to pull out of the API response.