@internetarchive/collection-browser 2.7.3 → 2.7.4

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.
@@ -1424,6 +1424,8 @@ export class CollectionBrowser
1424
1424
  if (oldObserver) this.disconnectResizeObserver(oldObserver);
1425
1425
  this.setupResizeObserver();
1426
1426
  }
1427
+
1428
+ this.ensureAvailableTilesDisplayed();
1427
1429
  }
1428
1430
 
1429
1431
  connectedCallback(): void {
@@ -1461,6 +1463,24 @@ export class CollectionBrowser
1461
1463
  this.updateLeftColumnHeight();
1462
1464
  }
1463
1465
 
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
+
1464
1484
  /**
1465
1485
  * Updates the data source with the current state of facet readiness for loading,
1466
1486
  * so that they will begin to load in at the appropriate time according to the
@@ -24,6 +24,7 @@ import filterIcon from '../../assets/img/icons/filter';
24
24
 
25
25
  import './smart-facet-button';
26
26
  import './smart-facet-dropdown';
27
+ import { log } from '../../utils/log';
27
28
 
28
29
  const fieldPrefixes: Partial<Record<FacetOption, string>> = {
29
30
  collection: 'Collection: ',
@@ -77,7 +78,7 @@ export class SmartFacetBar extends LitElement {
77
78
  let shouldUpdateSmartFacets = false;
78
79
 
79
80
  if (changed.has('query')) {
80
- console.log('query change', changed.get('query'), this.query);
81
+ log('query change', changed.get('query'), this.query);
81
82
  this.lastAggregations = undefined;
82
83
  shouldUpdateSmartFacets = true;
83
84
  }
@@ -88,25 +89,25 @@ export class SmartFacetBar extends LitElement {
88
89
  this.aggregations &&
89
90
  Object.keys(this.aggregations).length > 0
90
91
  ) {
91
- console.log('aggs change', changed.get('aggregations'), this.aggregations);
92
+ log('aggs change', changed.get('aggregations'), this.aggregations);
92
93
  this.lastAggregations = this.aggregations;
93
94
  shouldUpdateSmartFacets = true;
94
95
  }
95
96
 
96
97
  if (shouldUpdateSmartFacets) {
97
- console.log('should update smart facets, doing so...');
98
+ log('should update smart facets, doing so...');
98
99
  this.updateSmartFacets();
99
100
  }
100
101
  }
101
102
 
102
103
  private async updateSmartFacets(): Promise<void> {
103
- console.log('updating smart facets');
104
+ log('updating smart facets');
104
105
  if (this.query) {
105
106
  this.heuristicRecs =
106
107
  await new SmartQueryHeuristicGroup().getRecommendedFacets(this.query);
107
- console.log('heuristic recs are', this.heuristicRecs);
108
+ log('heuristic recs are', this.heuristicRecs);
108
109
  this.smartFacets = dedupe(this.facetsToDisplay);
109
- console.log('smart facets are', this.smartFacets);
110
+ log('smart facets are', this.smartFacets);
110
111
  }
111
112
  }
112
113
 
@@ -296,13 +297,15 @@ export class SmartFacetBar extends LitElement {
296
297
  }
297
298
 
298
299
  private onDropdownClick(e: CustomEvent<SmartFacetDropdown>): void {
299
- console.log('smart bar: onDropdownClick', e.detail);
300
- this.shadowRoot?.querySelectorAll('smart-facet-dropdown').forEach(dropdown => {
301
- if (dropdown !== e.detail) {
302
- console.log('closing', dropdown);
303
- (dropdown as SmartFacetDropdown).close();
304
- }
305
- });
300
+ log('smart bar: onDropdownClick', e.detail);
301
+ this.shadowRoot
302
+ ?.querySelectorAll('smart-facet-dropdown')
303
+ .forEach(dropdown => {
304
+ if (dropdown !== e.detail) {
305
+ log('closing', dropdown);
306
+ (dropdown as SmartFacetDropdown).close();
307
+ }
308
+ });
306
309
  }
307
310
 
308
311
  private filterToggleClicked(): void {
@@ -2,6 +2,7 @@ import { css, html, LitElement, CSSResultGroup, nothing } from 'lit';
2
2
  import { customElement, property, query } from 'lit/decorators.js';
3
3
  import type { IaDropdown, optionInterface } from '@internetarchive/ia-dropdown';
4
4
  import type { FacetRef, SmartFacet, SmartFacetEvent } from './models';
5
+ import { log } from '../../utils/log';
5
6
 
6
7
  @customElement('smart-facet-dropdown')
7
8
  export class SmartFacetDropdown extends LitElement {
@@ -36,7 +37,7 @@ export class SmartFacetDropdown extends LitElement {
36
37
  .options=${this.dropdownOptions}
37
38
  .selectedOption=${this.activeDropdownOption}
38
39
  @optionSelected=${this.optionSelected}
39
- @click=${this.onDropdownClick.bind(this)}
40
+ @click=${this.onDropdownClick}
40
41
  >
41
42
  <span class="dropdown-label" slot="dropdown-label"
42
43
  >${this.labelPrefix ?? nothing} ${displayText}</span
@@ -107,11 +108,10 @@ export class SmartFacetDropdown extends LitElement {
107
108
  }
108
109
 
109
110
  private onDropdownClick(): void {
110
- console.log('smart dropdown: onDropdownClick', this);
111
- this.dispatchEvent(new CustomEvent<SmartFacetDropdown>(
112
- 'dropdownClick',
113
- { detail: this }
114
- ));
111
+ log('smart dropdown: onDropdownClick', this);
112
+ this.dispatchEvent(
113
+ new CustomEvent<SmartFacetDropdown>('dropdownClick', { detail: this })
114
+ );
115
115
  }
116
116
 
117
117
  close(): void {
@@ -1048,12 +1048,12 @@ export class CollectionBrowserDataSource
1048
1048
  };
1049
1049
  params.uid = await this.requestUID(params, 'hits');
1050
1050
 
1051
- log('=== FIRING PAGE REQUEST ===', params);
1051
+ // log('=== FIRING PAGE REQUEST ===', params);
1052
1052
  const searchResponse = await this.host.searchService?.search(
1053
1053
  params,
1054
1054
  this.host.searchType
1055
1055
  );
1056
- log('=== RECEIVED PAGE RESPONSE IN CB ===', searchResponse);
1056
+ // log('=== RECEIVED PAGE RESPONSE IN CB ===', searchResponse);
1057
1057
  const success = searchResponse?.success;
1058
1058
 
1059
1059
  // This is checking to see if the fetch has been invalidated since it was fired off.
@@ -1120,19 +1120,21 @@ export class CollectionBrowserDataSource
1120
1120
 
1121
1121
  // Update the data source for each returned page.
1122
1122
  // 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) {
1127
1127
  numPages = Math.ceil(results.length / this.pageSize);
1128
1128
  this.endOfDataReached = true;
1129
1129
  if (this.activeOnHost) this.host.setTileCount(this.totalResults);
1130
1130
  }
1131
+
1131
1132
  for (let i = 0; i < numPages; i += 1) {
1132
1133
  const pageStartIndex = this.pageSize * i;
1133
1134
  this.addFetchedResultsToDataSource(
1134
1135
  pageNumber + i,
1135
- results.slice(pageStartIndex, pageStartIndex + this.pageSize)
1136
+ results.slice(pageStartIndex, pageStartIndex + this.pageSize),
1137
+ !isUnpagedElement || i === numPages - 1
1136
1138
  );
1137
1139
  }
1138
1140
  }
@@ -1157,16 +1159,17 @@ export class CollectionBrowserDataSource
1157
1159
  */
1158
1160
  private addFetchedResultsToDataSource(
1159
1161
  pageNumber: number,
1160
- results: SearchResult[]
1162
+ results: SearchResult[],
1163
+ needsReload = true
1161
1164
  ): void {
1162
1165
  const tiles: TileModel[] = [];
1163
1166
  results?.forEach(result => {
1164
1167
  if (!result.identifier) return;
1165
1168
  tiles.push(new TileModel(result));
1166
1169
  });
1170
+
1167
1171
  this.addPage(pageNumber, tiles);
1168
- const visiblePages = this.host.currentVisiblePageNumbers;
1169
- const needsReload = visiblePages.includes(pageNumber);
1172
+
1170
1173
  if (needsReload) {
1171
1174
  this.refreshVisibleResults();
1172
1175
  }