fix: pagination

This commit is contained in:
Torsten Dittmann committed 2022-10-26 19:52:49 +02:00
1 parent 1d9475a15d
commit 1ed702b352
2 files changed
+6 -7

No files matched your search

+3 -4
View File
@@ -4,11 +4,10 @@
export let offset: number;
export let path: string;
export let hidePages = false;
$: totalPages = Math.ceil(sum / limit);
$: currentPage = Math.floor(offset / limit + 1);
$: pages = pagination(currentPage, totalPages);
$: console.log({ sum, limit, totalPages, currentPage, pages });
function pagination(page: number, total: number) {
const pagesShown = 5;
const start = Math.max(
@@ -33,7 +32,7 @@
class:is-disabled={currentPage <= 1}
class="button is-text"
aria-label="prev page"
href={`${path}/${1}`}>
href={`${path}/${currentPage - 1}`}>
<span class="icon-cheveron-left" aria-hidden="true" />
<span class="text">Prev</span>
</a>
@@ -62,7 +61,7 @@
<a
class:is-disabled={currentPage === totalPages}
class="button is-text"
href={`${path}/${2}`}
href={`${path}/${currentPage + 1}`}
aria-label="next page">
<span class="text">Next</span>
<span class="icon-cheveron-right" aria-hidden="true" />
@@ -1,19 +1,19 @@
import { Query } from '@aw-labs/appwrite-console';
import { sdkForProject } from '$lib/stores/sdk';
import { pageToOffset } from '$lib/helpers/load';
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import { CARD_LIMIT, Dependencies } from '$lib/constants';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, parent, depends }) => {
await parent();
depends(Dependencies.FUNCTIONS);
const page = Number(params.page);
const offset = pageToOffset(page, PAGE_LIMIT);
const offset = pageToOffset(page, CARD_LIMIT);
return {
offset,
functions: await sdkForProject.functions.list([
Query.limit(PAGE_LIMIT),
Query.limit(CARD_LIMIT),
Query.offset(offset),
Query.orderDesc('$createdAt')
])