@internetarchive/collection-browser 4.3.2-alpha-webdev7939.0 → 4.3.2-alpha-webdev7939.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/app-root.js +676 -672
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/collection-browser.d.ts +23 -0
- package/dist/src/collection-browser.js +52 -3
- package/dist/src/collection-browser.js.map +1 -1
- package/package.json +2 -2
- package/src/app-root.ts +1254 -1251
- package/src/collection-browser.ts +57 -2
|
@@ -421,7 +421,7 @@ export class CollectionBrowser
|
|
|
421
421
|
const model = this.dataSource.getTileModelAt(index);
|
|
422
422
|
/**
|
|
423
423
|
* If we encounter a model we don't have yet and we're not in the middle of an
|
|
424
|
-
* automated scroll, fetch the page and
|
|
424
|
+
* automated scroll, schedule a fetch for the missing page and return undefined.
|
|
425
425
|
* The datasource will be updated once the page is loaded and the cell will be rendered.
|
|
426
426
|
*
|
|
427
427
|
* We disable it during the automated scroll since we don't want to fetch pages for intervening cells the
|
|
@@ -429,11 +429,61 @@ export class CollectionBrowser
|
|
|
429
429
|
*/
|
|
430
430
|
if (!model && !this.isScrollingToCell && this.dataSource.queryInitialized) {
|
|
431
431
|
const pageNumber = Math.floor(index / this.pageSize) + 1;
|
|
432
|
-
this.
|
|
432
|
+
this.scheduleDeferredPageFetch(pageNumber);
|
|
433
433
|
}
|
|
434
434
|
return model;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Debounce delay for page fetches initiated by new cells becoming visible.
|
|
439
|
+
* Tuned so quick scrolling through unloaded regions doesn't send rapid-fire
|
|
440
|
+
* search requests for every page we pass through, but to still feel responsive
|
|
441
|
+
* when the scroll ends.
|
|
442
|
+
*/
|
|
443
|
+
private static readonly DEFERRED_FETCH_DELAY_MS = 150;
|
|
444
|
+
|
|
445
|
+
private deferredFetchTimer = 0;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Schedules a fetch for the given page, debounced to ensure we don't
|
|
449
|
+
* rapid-fire fetches while scrolling through pages quickly.
|
|
450
|
+
*
|
|
451
|
+
* If there's no pending fetch timer yet, it will fire a fetch immediately.
|
|
452
|
+
* Otherwise, it will reset any existing timer. In either case, a deferred
|
|
453
|
+
* fetch for the visible pages is scheduled after a brief delay to account
|
|
454
|
+
* for whatever pages we land on after scrolling.
|
|
455
|
+
*/
|
|
456
|
+
private scheduleDeferredPageFetch(pageNumber: number): void {
|
|
457
|
+
if (!this.deferredFetchTimer) {
|
|
458
|
+
this.dataSource.fetchPage(pageNumber);
|
|
459
|
+
} else {
|
|
460
|
+
window.clearTimeout(this.deferredFetchTimer);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
this.deferredFetchTimer = window.setTimeout(() => {
|
|
464
|
+
this.deferredFetchTimer = 0;
|
|
465
|
+
this.fetchVisiblePages();
|
|
466
|
+
}, CollectionBrowser.DEFERRED_FETCH_DELAY_MS);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Fetch each currently-visible page whose first cell still has no
|
|
471
|
+
* loaded model.
|
|
472
|
+
*/
|
|
473
|
+
private fetchVisiblePages(): void {
|
|
474
|
+
const visibleIndices = this.infiniteScroller?.getVisibleCellIndices() ?? [];
|
|
475
|
+
const visiblePages = new Set(
|
|
476
|
+
visibleIndices.map(i => Math.floor(i / this.pageSize) + 1),
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
for (const page of visiblePages) {
|
|
480
|
+
const firstCellOfPage = (page - 1) * this.pageSize;
|
|
481
|
+
if (!this.dataSource.getTileModelAt(firstCellOfPage)) {
|
|
482
|
+
this.dataSource.fetchPage(page);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
437
487
|
// this is the total number of tiles we expect if
|
|
438
488
|
// the data returned is a full page worth
|
|
439
489
|
// this is useful for putting in placeholders for the expected number of tiles
|
|
@@ -1891,6 +1941,11 @@ export class CollectionBrowser
|
|
|
1891
1941
|
window.removeEventListener('popstate', this.boundNavigationHandler);
|
|
1892
1942
|
}
|
|
1893
1943
|
|
|
1944
|
+
if (this.deferredFetchTimer) {
|
|
1945
|
+
window.clearTimeout(this.deferredFetchTimer);
|
|
1946
|
+
this.deferredFetchTimer = 0;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1894
1949
|
this.leftColIntersectionObserver?.disconnect();
|
|
1895
1950
|
this.facetsIntersectionObserver?.disconnect();
|
|
1896
1951
|
window.removeEventListener('resize', this.updateLeftColumnHeight);
|