Skip to content

Commit b45b065

Browse files
authored
WEBDEV-7022 Ensure initial page of results always triggers scroller refresh (#402)
* Ensure initial page of results always triggers scroller refresh * Add additional logging * Adds monitor to ensure tile count reflects data size * Remove log statements
1 parent 5ad05dd commit b45b065

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/collection-browser.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,8 @@ export class CollectionBrowser
14241424
if (oldObserver) this.disconnectResizeObserver(oldObserver);
14251425
this.setupResizeObserver();
14261426
}
1427+
1428+
this.ensureAvailableTilesDisplayed();
14271429
}
14281430

14291431
connectedCallback(): void {
@@ -1461,6 +1463,24 @@ export class CollectionBrowser
14611463
this.updateLeftColumnHeight();
14621464
}
14631465

1466+
/**
1467+
* Ensures that if we have new results from the data source that are not yet
1468+
* displayed in the infinite scroller, that they are immediately reflected
1469+
* in the tile count.
1470+
*/
1471+
private ensureAvailableTilesDisplayed(): void {
1472+
if (
1473+
this.infiniteScroller &&
1474+
this.infiniteScroller.itemCount < this.dataSource.size
1475+
) {
1476+
this.setTileCount(
1477+
this.dataSource.endOfDataReached
1478+
? this.dataSource.size
1479+
: this.estimatedTileCount
1480+
);
1481+
}
1482+
}
1483+
14641484
/**
14651485
* Updates the data source with the current state of facet readiness for loading,
14661486
* so that they will begin to load in at the appropriate time according to the

src/data-source/collection-browser-data-source.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,19 +1120,21 @@ export class CollectionBrowserDataSource
11201120

11211121
// Update the data source for each returned page.
11221122
// For loans and web archives, we must account for receiving more pages than we asked for.
1123-
if (
1124-
this.host.profileElement === 'lending' ||
1125-
this.host.profileElement === 'web_archives'
1126-
) {
1123+
const isUnpagedElement = ['lending', 'web_archives'].includes(
1124+
this.host.profileElement!
1125+
);
1126+
if (isUnpagedElement) {
11271127
numPages = Math.ceil(results.length / this.pageSize);
11281128
this.endOfDataReached = true;
11291129
if (this.activeOnHost) this.host.setTileCount(this.totalResults);
11301130
}
1131+
11311132
for (let i = 0; i < numPages; i += 1) {
11321133
const pageStartIndex = this.pageSize * i;
11331134
this.addFetchedResultsToDataSource(
11341135
pageNumber + i,
1135-
results.slice(pageStartIndex, pageStartIndex + this.pageSize)
1136+
results.slice(pageStartIndex, pageStartIndex + this.pageSize),
1137+
!isUnpagedElement || i === numPages - 1
11361138
);
11371139
}
11381140
}
@@ -1157,16 +1159,17 @@ export class CollectionBrowserDataSource
11571159
*/
11581160
private addFetchedResultsToDataSource(
11591161
pageNumber: number,
1160-
results: SearchResult[]
1162+
results: SearchResult[],
1163+
needsReload = true
11611164
): void {
11621165
const tiles: TileModel[] = [];
11631166
results?.forEach(result => {
11641167
if (!result.identifier) return;
11651168
tiles.push(new TileModel(result));
11661169
});
1170+
11671171
this.addPage(pageNumber, tiles);
1168-
const visiblePages = this.host.currentVisiblePageNumbers;
1169-
const needsReload = visiblePages.includes(pageNumber);
1172+
11701173
if (needsReload) {
11711174
this.refreshVisibleResults();
11721175
}

0 commit comments

Comments
 (0)