-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathqueueListPagination.server.ts
More file actions
43 lines (38 loc) · 1.12 KB
/
Copy pathqueueListPagination.server.ts
File metadata and controls
43 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
export type QueueListFilteredPagination = {
mode: "filtered";
currentPage: number;
hasMore: boolean;
};
export type QueueListUnfilteredPagination = {
mode: "unfiltered";
currentPage: number;
totalPages: number;
count: number;
};
export type QueueListPagination = QueueListFilteredPagination | QueueListUnfilteredPagination;
export type OffsetLimitPagination = {
currentPage: number;
totalPages: number;
count: number;
};
/** Maps presenter pagination to the public API / SDK offset-limit contract. */
export function toOffsetLimitQueueListPagination(
pagination: QueueListPagination,
options: { itemsOnPage: number; perPage: number }
): OffsetLimitPagination {
if (pagination.mode === "unfiltered") {
return {
currentPage: pagination.currentPage,
totalPages: pagination.totalPages,
count: pagination.count,
};
}
return {
currentPage: pagination.currentPage,
totalPages: pagination.hasMore ? pagination.currentPage + 1 : pagination.currentPage,
count:
(pagination.currentPage - 1) * options.perPage +
options.itemsOnPage +
(pagination.hasMore ? 1 : 0),
};
}