Expand ISAC user operations
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { page as currentPage } from '$app/state';
|
||||
let { pagination }: { pagination: { page: number; perPage: number; total: number; pageCount: number } } = $props();
|
||||
let { pagination, namespace = '' }: { pagination: { page: number; perPage: number; total: number; pageCount: number }; namespace?: string } = $props();
|
||||
const href = (targetPage: number, perPage = pagination.perPage) => {
|
||||
const params = new URLSearchParams(currentPage.url.searchParams);
|
||||
params.set('page', String(targetPage));
|
||||
params.set('perPage', String(perPage));
|
||||
params.set(namespace ? `${namespace}Page` : 'page', String(targetPage));
|
||||
params.set(namespace ? `${namespace}PerPage` : 'perPage', String(perPage));
|
||||
return `${currentPage.url.pathname}?${params}`;
|
||||
};
|
||||
const visiblePages = $derived(
|
||||
|
||||
@@ -2,11 +2,13 @@ import type { URL } from 'node:url';
|
||||
|
||||
export const PAGE_SIZE_PRESETS = [10, 25, 50, 100] as const;
|
||||
|
||||
export function getPagination(url: URL, total: number) {
|
||||
const requestedSize = Number(url.searchParams.get('perPage'));
|
||||
export function getPagination(url: URL, total: number, namespace = '') {
|
||||
const pageKey = namespace ? `${namespace}Page` : 'page';
|
||||
const perPageKey = namespace ? `${namespace}PerPage` : 'perPage';
|
||||
const requestedSize = Number(url.searchParams.get(perPageKey));
|
||||
const perPage = PAGE_SIZE_PRESETS.includes(requestedSize as (typeof PAGE_SIZE_PRESETS)[number]) ? requestedSize : 25;
|
||||
const pageCount = Math.max(1, Math.ceil(total / perPage));
|
||||
const requestedPage = Number(url.searchParams.get('page'));
|
||||
const requestedPage = Number(url.searchParams.get(pageKey));
|
||||
const page = Math.min(pageCount, Math.max(1, Number.isInteger(requestedPage) ? requestedPage : 1));
|
||||
return {
|
||||
page,
|
||||
|
||||
Reference in New Issue
Block a user