Finally fix the build pagination issue

This commit is contained in:
2022-04-21 20:48:34 +02:00
parent 2881835dee
commit 5de0e3aa32
14 changed files with 336 additions and 406 deletions

View File

@ -0,0 +1,42 @@
import { splitEvery } from 'ramda'
export function parseParams(params: string) {
const splittedParams = params.split('/')
if (splittedParams.length % 2 !== 0) {
return []
}
const splits = splitEvery(2, splittedParams)
return Object.fromEntries(splits)
}
export function toParams(records: Record<string, string>) {
return Object.entries(records)
.map(([key, value]) => `${key}/${value}`)
.join('/')
}
export interface PaginationParams {
pageSize: number
page: number
filters?: Record<string, string>
}
export interface DropTakeParams {
offset: number
limit: number
}
/**
* Convert svelte `load` params into a `offset` and `limit` so they can be used to fetch endpoints with pagination queries
*/
export function getDropTakeFromPageParams(
pageSize: number,
page: number
): DropTakeParams {
const offset = pageSize * (page - 1)
const limit = pageSize
return {
offset,
limit,
}
}