Skip to content

Commit a0de07d

Browse files
committed
fix pagination on frontend
1 parent e220b1a commit a0de07d

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/pages/[owner]/[collection]/v/[n].astro

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ if (tab === "records" && currentType) {
4949
pageSize = 100;
5050
offset = (page - 1) * pageSize;
5151
const recordsRes = await fetch(`${apiBase}/api/collections/${owner}/${collection}/versions/${n}/records?type=${currentType}&limit=${pageSize}&offset=${offset}`, { headers });
52-
records = recordsRes.ok ? await recordsRes.json() : [];
52+
const recordsBody = recordsRes.ok ? await recordsRes.json() : { records: [], pagination: {} };
53+
records = recordsBody.records ?? recordsBody;
54+
totalRecords = recordsBody.pagination?.total ?? totalRecords;
5355
54-
// We need the total count for this type — get all records count per type from schema
55-
// For now, use the records returned and version.recordCount
56-
const allRecordsRes = await fetch(`${apiBase}/api/collections/${owner}/${collection}/versions/${n}/records?limit=1&offset=0&type=${currentType}`, { headers });
57-
// We'll use the version recordCount as an approximation; for type-specific counts we need to check
58-
// Actually, let's fetch a count per type from the full page
59-
totalPages = Math.ceil(records.length < pageSize ? 1 : totalRecords / pageSize);
56+
// We need the total count for this type — use pagination.total from the response
57+
totalPages = Math.ceil(totalRecords / pageSize) || 1;
6058
6159
pageNumbers = [];
6260
if (totalPages > 1) {

0 commit comments

Comments
 (0)