@@ -22,7 +22,7 @@ import {
2222 SortField ,
2323 SORT_OPTIONS ,
2424} from '../models' ;
25- import type { PageSpecifierParams } from './models' ;
25+ import { FACETLESS_PAGE_ELEMENTS , type PageSpecifierParams } from './models' ;
2626import type { CollectionBrowserDataSourceInterface } from './collection-browser-data-source-interface' ;
2727import type { CollectionBrowserSearchInterface } from './collection-browser-query-state' ;
2828import { sha1 } from '../utils/sha1' ;
@@ -31,10 +31,21 @@ import { log } from '../utils/log';
3131export class CollectionBrowserDataSource
3232 implements CollectionBrowserDataSourceInterface
3333{
34+ /**
35+ * All pages of tile models that have been fetched so far, indexed by their page
36+ * number (with the first being page 1).
37+ */
3438 private pages : Record < string , TileModel [ ] > = { } ;
3539
40+ /**
41+ * Tile offset to apply when looking up tiles in the pages, in order to maintain
42+ * page alignment after tiles are removed.
43+ */
3644 private offset = 0 ;
3745
46+ /**
47+ * Total number of tile models stored in this data source's pages
48+ */
3849 private numTileModels = 0 ;
3950
4051 /**
@@ -48,10 +59,21 @@ export class CollectionBrowserDataSource
4859 */
4960 private previousQueryKey : string = '' ;
5061
62+ /**
63+ * Whether the initial page of search results for the current query state
64+ * is presently being fetched.
65+ */
5166 private searchResultsLoading = false ;
5267
68+ /**
69+ * Whether the facets (aggregations) for the current query state are
70+ * presently being fetched.
71+ */
5372 private facetsLoading = false ;
5473
74+ /**
75+ * Whether further query changes should be ignored and not trigger fetches
76+ */
5577 private suppressFetches = false ;
5678
5779 /**
@@ -265,6 +287,13 @@ export class CollectionBrowserDataSource
265287 return Object . values ( this . pages ) . flat ( ) . indexOf ( tile ) ;
266288 }
267289
290+ /**
291+ * @inheritdoc
292+ */
293+ getPageSize ( ) : number {
294+ return this . pageSize ;
295+ }
296+
268297 /**
269298 * @inheritdoc
270299 */
@@ -294,11 +323,15 @@ export class CollectionBrowserDataSource
294323 this . _initialSearchCompleteResolver = res ;
295324 } ) ;
296325
326+ const shouldFetchFacets =
327+ ! this . host . suppressFacets &&
328+ ! FACETLESS_PAGE_ELEMENTS . includes ( this . host . profileElement ! ) ;
329+
297330 // Fire the initial page & facet requests
298331 this . queryInitialized = true ;
299332 await Promise . all ( [
300333 this . doInitialPageFetch ( ) ,
301- this . host . suppressFacets ? null : this . fetchFacets ( ) ,
334+ shouldFetchFacets ? this . fetchFacets ( ) : null ,
302335 ] ) ;
303336
304337 // Resolve the `initialSearchComplete` promise for this search
@@ -876,7 +909,7 @@ export class CollectionBrowserDataSource
876909
877910 // Batch multiple initial page requests together if needed (e.g., can request
878911 // pages 1 and 2 together in a single request).
879- const numPages = pageNumber === 1 ? numInitialPages : 1 ;
912+ let numPages = pageNumber === 1 ? numInitialPages : 1 ;
880913 const numRows = this . pageSize * numPages ;
881914
882915 // if a fetch is already in progress for this query and page, don't fetch again
@@ -990,7 +1023,16 @@ export class CollectionBrowserDataSource
9901023 }
9911024 }
9921025
993- // Update the data source for each returned page
1026+ // Update the data source for each returned page.
1027+ // For loans and web archives, we must account for receiving more pages than we asked for.
1028+ if (
1029+ this . host . profileElement === 'lending' ||
1030+ this . host . profileElement === 'web_archives'
1031+ ) {
1032+ numPages = Math . ceil ( results . length / this . pageSize ) ;
1033+ this . endOfDataReached = true ;
1034+ if ( this . activeOnHost ) this . host . setTileCount ( this . totalResults ) ;
1035+ }
9941036 for ( let i = 0 ; i < numPages ; i += 1 ) {
9951037 const pageStartIndex = this . pageSize * i ;
9961038 this . addTilesToDataSource (
0 commit comments