blob: f05492b34ff30ad402ac459f0eca4fa85772d1af (
plain) (
tree)
|
|
import { navigate } from '$lib/Navigation';
import { getContext, setContext } from 'svelte';
import { writable, type Writable } from 'svelte/store';
export interface PaginationData {
page: number;
items: number;
}
export class PaginationContext {
page = 0;
items = 0;
total = 0;
set update({ page, items }: PaginationData) {
this.page = page;
this.items = items;
}
apply(params: URLSearchParams) {
navigate({ pagination: { items: this.items } }, params);
}
}
export function initPaginationContext() {
return setContext<Writable<PaginationContext>>('pagination', writable(new PaginationContext()));
}
export function getPaginationContext() {
return getContext<Writable<PaginationContext>>('pagination');
}
|