mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
Implemented serverside pagination;
Enabled searchspace file mgmt panel to use serverside pagination;
This commit is contained in:
parent
54326be56c
commit
797fe26f53
7 changed files with 374 additions and 62 deletions
34
surfsense_web/lib/pagination.ts
Normal file
34
surfsense_web/lib/pagination.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Helper to normalize list responses from the API
|
||||
// Supports shapes: Array<T>, { items: T[]; total: number }, and tuple [T[], total]
|
||||
export type ListResponse<T> = {
|
||||
items: T[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
export function normalizeListResponse<T>(payload: any): ListResponse<T> {
|
||||
try {
|
||||
// Case 1: already in desired shape
|
||||
if (payload && Array.isArray(payload.items)) {
|
||||
const total = typeof payload.total === "number" ? payload.total : payload.items.length;
|
||||
return { items: payload.items as T[], total };
|
||||
}
|
||||
|
||||
// Case 2: tuple [items, total]
|
||||
if (Array.isArray(payload) && payload.length === 2 && Array.isArray(payload[0])) {
|
||||
const items = (payload[0] ?? []) as T[];
|
||||
const rawTotal = payload[1];
|
||||
const total = typeof rawTotal === "number" ? rawTotal : items.length;
|
||||
return { items, total };
|
||||
}
|
||||
|
||||
// Case 3: plain array
|
||||
if (Array.isArray(payload)) {
|
||||
return { items: payload as T[], total: (payload as T[]).length };
|
||||
}
|
||||
} catch (e) {
|
||||
// fallthrough to default
|
||||
}
|
||||
|
||||
return { items: [], total: 0 };
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue