Skip to content

Commit caf492e

Browse files
committed
Fix pagination logic
1 parent c0d7552 commit caf492e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

examples/react/saas-large/src/db/products.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ export const productsCollection = createCollection(
5151
const { subscription: _subscription, ...rest } = loadSubsetOptions
5252
console.log(JSON.stringify(rest))
5353
const page = computePageNumber(loadSubsetOptions.limit)
54-
const limit = loadSubsetOptions.limit + 1
54+
const limit = loadSubsetOptions.limit
5555
const orderBy = loadSubsetOptions.orderBy
5656
const where = loadSubsetOptions.where
5757

5858
const result = await getProducts({
5959
data: {
6060
page,
61-
limit,
61+
limit: limit ? limit + 1 : undefined,
6262
orderBy: orderBy ? JSON.stringify(orderBy) : undefined,
6363
where: where ? JSON.stringify(where) : undefined,
6464
},

examples/react/saas-large/src/lib/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ export const getProducts = createServerFn({ method: `GET` })
160160
})
161161
}
162162

163-
const startIndex = page * limit
164-
const endIndex = startIndex + limit
163+
const itemsPerPage = 50
164+
const startIndex = page * itemsPerPage
165+
const endIndex = limit
165166
const paginatedProducts = filteredProducts.slice(startIndex, endIndex)
166167

167168
return paginatedProducts

0 commit comments

Comments
 (0)