@@ -153,13 +153,7 @@ const completeSplitQuery =
153
153
* @param args - The arguments object for the query function, excluding
154
154
* the `paginationOpts` property. That property is injected by this hook.
155
155
* @param options - An object specifying the `initialNumItems` to be loaded in
156
- * the first page, and the `latestPageSize` to use.
157
- * @param options.latestPageSize controls how the latest page (the first page
158
- * until another page is loaded) size grows. With "fixed", the page size will
159
- * stay at the size specified by `initialNumItems` / `loadMore`. With "grow",
160
- * the page size will grow as new items are added within the range of the initial
161
- * page. Once multiple pages are loaded, all but the last page will grow, in
162
- * order to provide seamless pagination. See the docs for more details.
156
+ * the first page.
163
157
* @returns A {@link UsePaginatedQueryResult} that includes the currently loaded
164
158
* items, the status of the pagination, and a `loadMore` function.
165
159
*
@@ -168,10 +162,7 @@ const completeSplitQuery =
168
162
export function usePaginatedQuery < Query extends PaginatedQueryReference > (
169
163
query : Query ,
170
164
args : PaginatedQueryArgs < Query > | "skip" ,
171
- options : {
172
- initialNumItems : number ;
173
- latestPageSize ?: "grow" | "fixed" ;
174
- } ,
165
+ options : { initialNumItems : number } ,
175
166
) : UsePaginatedQueryReturnType < Query > {
176
167
if (
177
168
typeof options ?. initialNumItems !== "number" ||
@@ -247,9 +238,9 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
247
238
Value [ ] ,
248
239
undefined | PaginationResult < Value > ,
249
240
] = useMemo ( ( ) => {
250
- let currResult : PaginationResult < Value > | undefined = undefined ;
241
+ let currResult = undefined ;
251
242
252
- const allItems : Value [ ] = [ ] ;
243
+ const allItems = [ ] ;
253
244
for ( const pageKey of currState . pageKeys ) {
254
245
currResult = resultsObject [ pageKey ] ;
255
246
if ( currResult === undefined ) {
@@ -362,33 +353,9 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
362
353
if ( ! alreadyLoadingMore ) {
363
354
alreadyLoadingMore = true ;
364
355
setState ( ( prevState ) => {
365
- let nextPageKey = prevState . nextPageKey ;
356
+ const pageKeys = [ ... prevState . pageKeys , prevState . nextPageKey ] ;
366
357
const queries = { ...prevState . queries } ;
367
- let ongoingSplits = prevState . ongoingSplits ;
368
- let pageKeys = prevState . pageKeys ;
369
- if ( options . latestPageSize === "fixed" ) {
370
- const lastPageKey = prevState . pageKeys . at ( - 1 ) ! ;
371
- const boundLastPageKey = nextPageKey ;
372
- queries [ boundLastPageKey ] = {
373
- query : prevState . query ,
374
- args : {
375
- ...prevState . args ,
376
- paginationOpts : {
377
- ...( queries [ lastPageKey ] ! . args
378
- . paginationOpts as unknown as PaginationOptions ) ,
379
- endCursor : continueCursor ,
380
- } ,
381
- } ,
382
- } ;
383
- nextPageKey ++ ;
384
- ongoingSplits = {
385
- ...ongoingSplits ,
386
- [ lastPageKey ] : [ boundLastPageKey , nextPageKey ] ,
387
- } ;
388
- } else {
389
- pageKeys = [ ...prevState . pageKeys , nextPageKey ] ;
390
- }
391
- queries [ nextPageKey ] = {
358
+ queries [ prevState . nextPageKey ] = {
392
359
query : prevState . query ,
393
360
args : {
394
361
...prevState . args ,
@@ -399,19 +366,17 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
399
366
} ,
400
367
} ,
401
368
} ;
402
- nextPageKey ++ ;
403
369
return {
404
370
...prevState ,
371
+ nextPageKey : prevState . nextPageKey + 1 ,
405
372
pageKeys,
406
- nextPageKey,
407
373
queries,
408
- ongoingSplits,
409
374
} ;
410
375
} ) ;
411
376
}
412
377
} ,
413
378
} as const ;
414
- } , [ maybeLastResult , currState . nextPageKey , options . latestPageSize ] ) ;
379
+ } , [ maybeLastResult , currState . nextPageKey ] ) ;
415
380
416
381
return {
417
382
results,
0 commit comments