From 5529352f2cddcb8c32b22abb1ec4b9df80e0ebd6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 11 Jul 2022 12:32:09 +0200 Subject: [PATCH] fix: pagination --- src/lib/components/pagination.svelte | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index 6c894b5b9..f11366e28 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -5,15 +5,15 @@ export let offset: number; const dispatch = createEventDispatcher(); - const totalPages = Math.ceil(sum / limit); - let currentPage = Math.floor(offset / limit + 1); + $: totalPages = Math.ceil(sum / limit); + $: currentPage = Math.floor(offset / limit + 1); + $: pages = pagination(currentPage, totalPages); function handleOptionClick(page: number) { if (currentPage !== page) { offset = limit * (page - 1); currentPage = page; dispatch('change'); - pages = pagination(currentPage, totalPages); } } @@ -22,17 +22,13 @@ currentPage += 1; offset = limit * (currentPage - 1); dispatch('change'); - pages = pagination(currentPage, totalPages); } else if (direction === 'prev' && currentPage > 1) { currentPage -= 1; offset = limit * (currentPage - 1); dispatch('change'); - pages = pagination(currentPage, totalPages); } } - let pages = pagination(currentPage, totalPages); - function pagination(page: number, total: number) { const pagesShown = 5; const start = Math.max(