Skip to content

Commit

Permalink
Merge b207957 into 75f9ee0
Browse files Browse the repository at this point in the history
  • Loading branch information
blerrgh committed Jan 19, 2023
2 parents 75f9ee0 + b207957 commit a064fd6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib/plugins/addPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface PaginationState {
pageSize: Writable<number>;
pageIndex: Writable<number>;
pageCount: Readable<number>;
serverItemsCount: Writable<number>;
serverItemCount: Writable<number>;
hasPreviousPage: Readable<boolean>;
hasNextPage: Readable<boolean>;
}
Expand All @@ -36,11 +36,11 @@ export const createPageStore = ({

const pageIndex = writable(initialPageIndex);

function calcPageCountAndLimitIndex([$pageSize, $itemsCount]: [
function calcPageCountAndLimitIndex([$pageSize, $itemCount]: [
$pageSize: number,
$itemsCount: number
$itemCount: number
]) {
const $pageCount = Math.ceil($itemsCount / $pageSize);
const $pageCount = Math.ceil($itemCount / $pageSize);
pageIndex.update(($pageIndex) => {
if ($pageCount > 0 && $pageIndex >= $pageCount) {
return $pageCount - 1;
Expand All @@ -50,10 +50,10 @@ export const createPageStore = ({
return $pageCount;
}

const serverItemsCount = writable(0);
const serverItemCount = writable(0);
let pageCount;
if (serverSide) {
pageCount = derived([pageSize, serverItemsCount], calcPageCountAndLimitIndex);
pageCount = derived([pageSize, serverItemCount], calcPageCountAndLimitIndex);
} else {
const itemCount = derived(items, ($items) => $items.length);
pageCount = derived([pageSize, itemCount], calcPageCountAndLimitIndex);
Expand All @@ -74,7 +74,7 @@ export const createPageStore = ({
},
pageIndex,
pageCount,
serverItemsCount,
serverItemCount,
hasPreviousPage,
hasNextPage,
};
Expand All @@ -101,7 +101,7 @@ export const addPagination =
() => {
const prePaginatedRows = writable<BodyRow<Item>[]>([]);
const paginatedRows = writable<BodyRow<Item>[]>([]);
const { pageSize, pageIndex, pageCount, serverItemsCount, hasPreviousPage, hasNextPage } =
const { pageSize, pageIndex, pageCount, serverItemCount, hasPreviousPage, hasNextPage } =
createPageStore({
items: prePaginatedRows,
initialPageIndex,
Expand All @@ -112,7 +112,7 @@ export const addPagination =
pageSize,
pageIndex,
pageCount,
serverItemsCount,
serverItemCount,
hasPreviousPage,
hasNextPage,
};
Expand Down

0 comments on commit a064fd6

Please sign in to comment.