Skip to content

Commit

Permalink
Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 11, 2024
1 parent cd95cdb commit 4f02ddc
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/routes/app/add-ons/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
export let data;
function gotoPage(pageUrl: string) {
// TODO: Improve cursor handling in page data responses
/** The pagination URL provided in the reponse corresponds to an API query.
* This gets the cursor from the pagination URL and uses it to update the
* current URL's searchParams value (there should be a smarter way to do this).
*/
function paginate(pageUrl: string) {
const { url } = data;
const cursor = new URL(pageUrl).searchParams.get("cursor");
if (!cursor) return;
Expand Down Expand Up @@ -71,12 +76,16 @@

<PageToolbar slot="footer">
<svelte:fragment slot="center">
<Paginator
has_next={Boolean(data.next_url)}
has_previous={Boolean(data.previous_url)}
on:next={() => gotoPage(data.next_url)}
on:previous={() => gotoPage(data.previous_url)}
/>
{#await data.addons}
<Paginator />
{:then page}
<Paginator
has_next={Boolean(page.next_url)}
has_previous={Boolean(page.previous_url)}
on:next={() => paginate(page.next_url)}
on:previous={() => paginate(page.previous_url)}
/>
{/await}
</svelte:fragment>
</PageToolbar>
</ContentLayout>
Expand Down

0 comments on commit 4f02ddc

Please sign in to comment.