@internetarchive/collection-browser 0.3.2-alpha.4 → 0.3.2

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.
Files changed (218) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +26 -26
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/LICENSE +661 -661
  8. package/README.md +83 -83
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +9 -9
  11. package/dist/src/app-root.d.ts +43 -43
  12. package/dist/src/app-root.js +233 -233
  13. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  14. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  15. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  16. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  17. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  18. package/dist/src/assets/img/icons/chevron.js +2 -2
  19. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  20. package/dist/src/assets/img/icons/empty-query.js +2 -2
  21. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  22. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  23. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  24. package/dist/src/assets/img/icons/eye.js +2 -2
  25. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  26. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  27. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  28. package/dist/src/assets/img/icons/login-required.js +2 -2
  29. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  30. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  31. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  32. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  33. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  34. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  35. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  36. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  37. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  38. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  39. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  40. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  41. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  42. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  43. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  44. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  45. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  46. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  47. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  48. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  49. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  50. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  51. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  52. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  53. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  54. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  55. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  56. package/dist/src/assets/img/icons/null-result.js +2 -2
  57. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  58. package/dist/src/assets/img/icons/restricted.js +2 -2
  59. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  60. package/dist/src/assets/img/icons/reviews.js +2 -2
  61. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  62. package/dist/src/assets/img/icons/upload.js +2 -2
  63. package/dist/src/assets/img/icons/views.d.ts +1 -1
  64. package/dist/src/assets/img/icons/views.js +2 -2
  65. package/dist/src/circular-activity-indicator.d.ts +5 -5
  66. package/dist/src/circular-activity-indicator.js +17 -17
  67. package/dist/src/collection-browser.d.ts +247 -247
  68. package/dist/src/collection-browser.js +1419 -1418
  69. package/dist/src/collection-browser.js.map +1 -1
  70. package/dist/src/collection-facets/facets-template.d.ts +16 -16
  71. package/dist/src/collection-facets/facets-template.js +125 -125
  72. package/dist/src/collection-facets/more-facets-content.d.ts +74 -74
  73. package/dist/src/collection-facets/more-facets-content.js +330 -330
  74. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  75. package/dist/src/collection-facets/more-facets-pagination.js +192 -192
  76. package/dist/src/collection-facets.d.ts +73 -73
  77. package/dist/src/collection-facets.js +507 -507
  78. package/dist/src/collection-facets.js.map +1 -1
  79. package/dist/src/empty-placeholder.d.ts +11 -11
  80. package/dist/src/empty-placeholder.js +42 -42
  81. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  82. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  83. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  84. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  85. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  86. package/dist/src/mediatype/mediatype-config.js +85 -85
  87. package/dist/src/models.d.ts +97 -97
  88. package/dist/src/models.js +100 -100
  89. package/dist/src/restoration-state-handler.d.ts +45 -45
  90. package/dist/src/restoration-state-handler.js +220 -220
  91. package/dist/src/sort-filter-bar/alpha-bar.d.ts +9 -9
  92. package/dist/src/sort-filter-bar/alpha-bar.js +41 -41
  93. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  94. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  95. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  96. package/dist/src/sort-filter-bar/img/list.js +2 -2
  97. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  98. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  99. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  100. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  101. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +107 -107
  102. package/dist/src/sort-filter-bar/sort-filter-bar.js +423 -423
  103. package/dist/src/styles/item-image-styles.d.ts +8 -8
  104. package/dist/src/styles/item-image-styles.js +9 -9
  105. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  106. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  107. package/dist/src/tiles/grid/account-tile.d.ts +8 -8
  108. package/dist/src/tiles/grid/account-tile.js +20 -20
  109. package/dist/src/tiles/grid/collection-tile.d.ts +7 -7
  110. package/dist/src/tiles/grid/collection-tile.js +23 -23
  111. package/dist/src/tiles/grid/item-tile.d.ts +24 -24
  112. package/dist/src/tiles/grid/item-tile.js +87 -87
  113. package/dist/src/tiles/grid/tile-stats.d.ts +10 -10
  114. package/dist/src/tiles/grid/tile-stats.js +35 -35
  115. package/dist/src/tiles/image-block.d.ts +17 -17
  116. package/dist/src/tiles/image-block.js +69 -73
  117. package/dist/src/tiles/image-block.js.map +1 -1
  118. package/dist/src/tiles/item-image.d.ts +31 -31
  119. package/dist/src/tiles/item-image.js +103 -103
  120. package/dist/src/tiles/list/account-label.d.ts +1 -1
  121. package/dist/src/tiles/list/account-label.js +6 -6
  122. package/dist/src/tiles/list/date-label.d.ts +1 -1
  123. package/dist/src/tiles/list/date-label.js +12 -12
  124. package/dist/src/tiles/list/tile-list-compact-header.d.ts +12 -12
  125. package/dist/src/tiles/list/tile-list-compact-header.js +41 -41
  126. package/dist/src/tiles/list/tile-list-compact.d.ts +20 -20
  127. package/dist/src/tiles/list/tile-list-compact.js +88 -87
  128. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  129. package/dist/src/tiles/list/tile-list.d.ts +50 -50
  130. package/dist/src/tiles/list/tile-list.js +265 -264
  131. package/dist/src/tiles/list/tile-list.js.map +1 -1
  132. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  133. package/dist/src/tiles/mediatype-icon.js +47 -47
  134. package/dist/src/tiles/overlay/icon-overlay.d.ts +7 -7
  135. package/dist/src/tiles/overlay/icon-overlay.js +30 -31
  136. package/dist/src/tiles/overlay/icon-overlay.js.map +1 -1
  137. package/dist/src/tiles/overlay/text-overlay.d.ts +8 -8
  138. package/dist/src/tiles/overlay/text-overlay.js +31 -31
  139. package/dist/src/tiles/text-snippet-block.d.ts +29 -29
  140. package/dist/src/tiles/text-snippet-block.js +81 -81
  141. package/dist/src/tiles/tile-dispatcher.d.ts +36 -36
  142. package/dist/src/tiles/tile-dispatcher.js +128 -128
  143. package/dist/src/utils/analytics-events.d.ts +18 -18
  144. package/dist/src/utils/analytics-events.js +20 -20
  145. package/dist/src/utils/format-count.d.ts +7 -7
  146. package/dist/src/utils/format-count.js +76 -76
  147. package/dist/src/utils/format-date.d.ts +2 -2
  148. package/dist/src/utils/format-date.js +23 -23
  149. package/dist/test/collection-browser.test.d.ts +1 -1
  150. package/dist/test/collection-browser.test.js +333 -318
  151. package/dist/test/collection-browser.test.js.map +1 -1
  152. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  153. package/dist/test/collection-facets/facets-template.test.js +62 -62
  154. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  155. package/dist/test/collection-facets/more-facets-content.test.js +91 -91
  156. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  157. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  158. package/dist/test/collection-facets.test.d.ts +2 -2
  159. package/dist/test/collection-facets.test.js +423 -423
  160. package/dist/test/collection-facets.test.js.map +1 -1
  161. package/dist/test/empty-placeholder.test.d.ts +1 -1
  162. package/dist/test/empty-placeholder.test.js +33 -33
  163. package/dist/test/icon-overlay.test.d.ts +1 -1
  164. package/dist/test/icon-overlay.test.js +24 -24
  165. package/dist/test/image-block.test.d.ts +1 -0
  166. package/dist/test/image-block.test.js +79 -0
  167. package/dist/test/image-block.test.js.map +1 -0
  168. package/dist/test/item-image.test.d.ts +1 -1
  169. package/dist/test/item-image.test.js +56 -56
  170. package/dist/test/mediatype-config.test.d.ts +1 -1
  171. package/dist/test/mediatype-config.test.js +16 -16
  172. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  173. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  174. package/dist/test/mocks/mock-collection-name-cache.d.ts +7 -7
  175. package/dist/test/mocks/mock-collection-name-cache.js +13 -13
  176. package/dist/test/mocks/mock-search-responses.d.ts +5 -5
  177. package/dist/test/mocks/mock-search-responses.js +103 -103
  178. package/dist/test/mocks/mock-search-service.d.ts +13 -13
  179. package/dist/test/mocks/mock-search-service.js +25 -25
  180. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  181. package/dist/test/restoration-state-handler.test.js +117 -117
  182. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  183. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +113 -113
  184. package/dist/test/text-overlay.test.d.ts +1 -1
  185. package/dist/test/text-overlay.test.js +41 -41
  186. package/dist/test/text-snippet-block.test.d.ts +1 -1
  187. package/dist/test/text-snippet-block.test.js +57 -57
  188. package/dist/test/tile-stats.test.d.ts +1 -1
  189. package/dist/test/tile-stats.test.js +33 -33
  190. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  191. package/dist/test/tiles/grid/item-tile.test.js +107 -107
  192. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -0
  193. package/dist/test/tiles/list/tile-list-compact.test.js +31 -0
  194. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -0
  195. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  196. package/dist/test/tiles/list/tile-list.test.js +36 -36
  197. package/dist/test/utils/format-count.test.d.ts +1 -1
  198. package/dist/test/utils/format-count.test.js +23 -23
  199. package/dist/test/utils/format-date.test.d.ts +1 -1
  200. package/dist/test/utils/format-date.test.js +17 -17
  201. package/index.html +24 -24
  202. package/local.archive.org.cert +86 -86
  203. package/local.archive.org.key +27 -27
  204. package/package.json +115 -115
  205. package/renovate.json +6 -6
  206. package/src/collection-browser.ts +1547 -1547
  207. package/src/collection-facets.ts +582 -582
  208. package/src/tiles/image-block.ts +7 -10
  209. package/src/tiles/list/tile-list-compact.ts +1 -0
  210. package/src/tiles/list/tile-list.ts +1 -0
  211. package/src/tiles/overlay/icon-overlay.ts +3 -4
  212. package/test/collection-browser.test.ts +24 -1
  213. package/test/collection-facets.test.ts +556 -556
  214. package/test/image-block.test.ts +86 -0
  215. package/test/tiles/list/tile-list-compact.test.ts +38 -0
  216. package/tsconfig.json +21 -21
  217. package/web-dev-server.config.mjs +30 -30
  218. package/web-test-runner.config.mjs +41 -41
@@ -1,1547 +1,1547 @@
1
- /* eslint-disable import/no-duplicates */
2
- import {
3
- html,
4
- css,
5
- LitElement,
6
- PropertyValues,
7
- TemplateResult,
8
- nothing,
9
- } from 'lit';
10
- import { customElement, property, query, state } from 'lit/decorators.js';
11
- import { ifDefined } from 'lit/directives/if-defined.js';
12
-
13
- import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
14
- import type {
15
- InfiniteScroller,
16
- InfiniteScrollerCellProviderInterface,
17
- } from '@internetarchive/infinite-scroller';
18
- import {
19
- Aggregation,
20
- SearchParams,
21
- SearchResult,
22
- SearchServiceInterface,
23
- SearchType,
24
- SortDirection,
25
- SortParam,
26
- } from '@internetarchive/search-service';
27
- import type {
28
- SharedResizeObserverInterface,
29
- SharedResizeObserverResizeHandlerInterface,
30
- } from '@internetarchive/shared-resize-observer';
31
- import '@internetarchive/infinite-scroller';
32
- import type { CollectionNameCacheInterface } from '@internetarchive/collection-name-cache';
33
- import type { ModalManagerInterface } from '@internetarchive/modal-manager';
34
- import './tiles/tile-dispatcher';
35
- import './tiles/collection-browser-loading-tile';
36
- import './sort-filter-bar/sort-filter-bar';
37
- import './collection-facets';
38
- import './circular-activity-indicator';
39
- import './sort-filter-bar/sort-filter-bar';
40
- import {
41
- SelectedFacets,
42
- SortField,
43
- SortFieldToMetadataField,
44
- CollectionBrowserContext,
45
- defaultSelectedFacets,
46
- TileModel,
47
- CollectionDisplayMode,
48
- FacetOption,
49
- } from './models';
50
- import {
51
- RestorationStateHandlerInterface,
52
- RestorationStateHandler,
53
- RestorationState,
54
- } from './restoration-state-handler';
55
- import chevronIcon from './assets/img/icons/chevron';
56
- import { LanguageCodeHandler } from './language-code-handler/language-code-handler';
57
- import type { PlaceholderType } from './empty-placeholder';
58
- import './empty-placeholder';
59
-
60
- import {
61
- analyticsActions,
62
- analyticsCategories,
63
- } from './utils/analytics-events';
64
-
65
- @customElement('collection-browser')
66
- export class CollectionBrowser
67
- extends LitElement
68
- implements
69
- InfiniteScrollerCellProviderInterface,
70
- SharedResizeObserverResizeHandlerInterface
71
- {
72
- @property({ type: String }) baseNavigationUrl?: string;
73
-
74
- @property({ type: String }) baseImageUrl: string = 'https://archive.org';
75
-
76
- @property({ type: Object }) searchService?: SearchServiceInterface;
77
-
78
- @property({ type: String }) searchType: SearchType = SearchType.METADATA;
79
-
80
- @property({ type: String }) baseQuery?: string;
81
-
82
- @property({ type: String }) displayMode?: CollectionDisplayMode;
83
-
84
- @property({ type: Object }) sortParam: SortParam | null = null;
85
-
86
- @property({ type: String }) selectedSort: SortField = SortField.relevance;
87
-
88
- @property({ type: String }) selectedTitleFilter: string | null = null;
89
-
90
- @property({ type: String }) selectedCreatorFilter: string | null = null;
91
-
92
- @property({ type: String }) sortDirection: SortDirection | null = null;
93
-
94
- @property({ type: String }) dateRangeQueryClause?: string;
95
-
96
- @property({ type: Number }) pageSize = 50;
97
-
98
- @property({ type: Object }) resizeObserver?: SharedResizeObserverInterface;
99
-
100
- @property({ type: String }) titleQuery?: string;
101
-
102
- @property({ type: String }) creatorQuery?: string;
103
-
104
- @property({ type: Number }) currentPage?: number;
105
-
106
- @property({ type: String }) minSelectedDate?: string;
107
-
108
- @property({ type: String }) maxSelectedDate?: string;
109
-
110
- @property({ type: Object }) selectedFacets?: SelectedFacets;
111
-
112
- @property({ type: Boolean }) showHistogramDatePicker = false;
113
-
114
- /** describes where this component is being used */
115
- @property({ type: String, reflect: true }) searchContext: string =
116
- analyticsCategories.default;
117
-
118
- @property({ type: Object })
119
- collectionNameCache?: CollectionNameCacheInterface;
120
-
121
- @property({ type: String }) pageContext: CollectionBrowserContext = 'search';
122
-
123
- @property({ type: Object })
124
- restorationStateHandler: RestorationStateHandlerInterface = new RestorationStateHandler(
125
- {
126
- context: this.pageContext,
127
- }
128
- );
129
-
130
- @property({ type: Number }) mobileBreakpoint = 600;
131
-
132
- @property({ type: Boolean }) loggedIn = false;
133
-
134
- @property({ type: Object }) modalManager?: ModalManagerInterface = undefined;
135
-
136
- /**
137
- * If item management UI active
138
- */
139
- @property({ type: Boolean }) isManageView = false;
140
-
141
- /**
142
- * The page that the consumer wants to load.
143
- */
144
- private initialPageNumber = 1;
145
-
146
- /**
147
- * This the the number of pages that we want to show.
148
- *
149
- * The data isn't necessarily loaded for all of the pages, but this lets us
150
- * know how many cells we should render.
151
- */
152
- @state() private pagesToRender = this.initialPageNumber;
153
-
154
- @state() private searchResultsLoading = false;
155
-
156
- @state() private facetsLoading = false;
157
-
158
- @state() private lendingFacetLoading = false;
159
-
160
- @state() private fullYearAggregationLoading = false;
161
-
162
- @state() private aggregations?: Record<string, Aggregation>;
163
-
164
- @state() private fullYearsHistogramAggregation: Aggregation | undefined;
165
-
166
- /**
167
- * The search type of the previous search (i.e., the currently displayed
168
- * search results), which may differ from the one that is currently selected
169
- * to be used for the next search.
170
- */
171
- @state() private previousSearchType?: SearchType;
172
-
173
- @state() private totalResults?: number;
174
-
175
- @state() private mobileView = false;
176
-
177
- @state() private mobileFacetsVisible = false;
178
-
179
- @state() private placeholderType: PlaceholderType = null;
180
-
181
- @query('#content-container') private contentContainer!: HTMLDivElement;
182
-
183
- private languageCodeHandler = new LanguageCodeHandler();
184
-
185
- @property({ type: Object, attribute: false })
186
- private analyticsHandler?: AnalyticsManagerInterface;
187
-
188
- /**
189
- * When we're animated scrolling to the page, we don't want to fetch
190
- * all of the pages as it scrolls so this lets us know if we're scrolling
191
- */
192
- private isScrollingToCell = false;
193
-
194
- /**
195
- * When we've reached the end of the data, stop trying to fetch more
196
- */
197
- private endOfDataReached = false;
198
-
199
- /**
200
- * When page width resizes from desktop to mobile, set true to
201
- * disable expand/collapse transition when loading.
202
- */
203
- private isResizeToMobile = false;
204
-
205
- private placeholderCellTemplate = html`<collection-browser-loading-tile></collection-browser-loading-tile>`;
206
-
207
- private tileModelAtCellIndex(index: number): TileModel | undefined {
208
- const pageNumber = Math.floor(index / this.pageSize) + 1;
209
- const itemIndex = index % this.pageSize;
210
- const model = this.dataSource[pageNumber]?.[itemIndex];
211
- /**
212
- * If we encounter a model we don't have yet and we're not in the middle of an
213
- * automated scroll, fetch the page and just return undefined.
214
- * The datasource will be updated once the page is loaded and the cell will be rendered.
215
- *
216
- * We disable it during the automated scroll since we may fetch pages for cells the
217
- * user may never see.
218
- */
219
- if (!model && !this.isScrollingToCell) {
220
- this.fetchPage(pageNumber);
221
- }
222
- return model;
223
- }
224
-
225
- private get sortFilterQueries(): string {
226
- const queries = [this.titleQuery, this.creatorQuery];
227
- return queries.filter(q => q).join(' AND ');
228
- }
229
-
230
- // this is the total number of tiles we expect if
231
- // the data returned is a full page worth
232
- // this is useful for putting in placeholders for the expected number of tiles
233
- private get estimatedTileCount(): number {
234
- return this.pagesToRender * this.pageSize;
235
- }
236
-
237
- // this is the actual number of tiles in the datasource,
238
- // which is useful for removing excess placeholder tiles
239
- // once we reached the end of the data
240
- private get actualTileCount(): number {
241
- return Object.keys(this.dataSource).reduce(
242
- (acc, page) => acc + this.dataSource[page].length,
243
- 0
244
- );
245
- }
246
-
247
- /**
248
- * The results per page so we can paginate.
249
- *
250
- * This allows us to start in the middle of the search results and
251
- * fetch data before or after the current page. If we don't have a key
252
- * for the previous/next page, we'll fetch the next/previous page to populate it
253
- */
254
- private dataSource: Record<string, TileModel[]> = {};
255
-
256
- @query('infinite-scroller')
257
- private infiniteScroller!: InfiniteScroller;
258
-
259
- /**
260
- * Go to the given page of results
261
- *
262
- * @param pageNumber
263
- */
264
- goToPage(pageNumber: number) {
265
- this.initialPageNumber = pageNumber;
266
- this.pagesToRender = pageNumber;
267
- this.scrollToPage(pageNumber);
268
- }
269
-
270
- clearFilters() {
271
- this.selectedFacets = defaultSelectedFacets;
272
- this.sortParam = null;
273
- this.selectedTitleFilter = null;
274
- this.selectedCreatorFilter = null;
275
- this.titleQuery = undefined;
276
- this.creatorQuery = undefined;
277
- this.selectedSort = SortField.relevance;
278
- this.sortDirection = null;
279
- }
280
-
281
- /**
282
- * Manually requests to perform a search, which will only be executed if one of
283
- * the query, the search type, or the sort has changed.
284
- */
285
- requestSearch() {
286
- this.handleQueryChange();
287
- }
288
-
289
- render() {
290
- this.setPlaceholderType();
291
- return html`
292
- <div
293
- id="content-container"
294
- class=${this.mobileView ? 'mobile' : 'desktop'}
295
- >
296
- ${this.placeholderType
297
- ? this.emptyPlaceholderTemplate
298
- : this.collectionBrowserTemplate}
299
- </div>
300
- `;
301
- }
302
-
303
- private setPlaceholderType() {
304
- this.placeholderType = null;
305
- if (!this.baseQuery) {
306
- this.placeholderType = 'empty-query';
307
- }
308
-
309
- if (!this.searchResultsLoading && this.totalResults === 0) {
310
- this.placeholderType = 'null-result';
311
- }
312
- }
313
-
314
- private get emptyPlaceholderTemplate() {
315
- return html`
316
- <empty-placeholder
317
- .placeholderType=${this.placeholderType}
318
- ?isMobileView=${this.mobileView}
319
- ></empty-placeholder>
320
- `;
321
- }
322
-
323
- private get collectionBrowserTemplate() {
324
- return html`<div
325
- id="left-column"
326
- class="column${this.isResizeToMobile ? ' preload' : ''}"
327
- >
328
- <div id="mobile-header-container">
329
- ${this.mobileView ? this.mobileFacetsTemplate : nothing}
330
- <div id="results-total">
331
- <span id="big-results-count">
332
- ${this.totalResults !== undefined
333
- ? this.totalResults.toLocaleString()
334
- : '-'}
335
- </span>
336
- <span id="big-results-label">
337
- ${this.totalResults === 1 ? 'Result' : 'Results'}
338
- </span>
339
- </div>
340
- </div>
341
- <div
342
- id="facets-container"
343
- class=${!this.mobileView || this.mobileFacetsVisible
344
- ? 'expanded'
345
- : ''}
346
- >
347
- ${this.facetsTemplate}
348
- </div>
349
- </div>
350
- <div id="right-column" class="column">
351
- ${this.searchResultsLoading ? this.loadingTemplate : nothing}
352
- ${this.sortFilterBarTemplate}
353
- ${this.displayMode === `list-compact`
354
- ? this.listHeaderTemplate
355
- : nothing}
356
- ${this.infiniteScrollerTemplate}
357
- </div>`;
358
- }
359
-
360
- private get infiniteScrollerTemplate() {
361
- return html`<infinite-scroller
362
- class="${ifDefined(this.displayMode)}"
363
- .cellProvider=${this}
364
- .placeholderCellTemplate=${this.placeholderCellTemplate}
365
- @scrollThresholdReached=${this.scrollThresholdReached}
366
- @visibleCellsChanged=${this.visibleCellsChanged}
367
- ></infinite-scroller>`;
368
- }
369
-
370
- private get sortFilterBarTemplate() {
371
- return html`
372
- <sort-filter-bar
373
- .selectedSort=${this.selectedSort}
374
- .sortDirection=${this.sortDirection}
375
- .displayMode=${this.displayMode}
376
- .selectedTitleFilter=${this.selectedTitleFilter}
377
- .selectedCreatorFilter=${this.selectedCreatorFilter}
378
- .resizeObserver=${this.resizeObserver}
379
- @sortChanged=${this.userChangedSort}
380
- @displayModeChanged=${this.displayModeChanged}
381
- @titleLetterChanged=${this.titleLetterSelected}
382
- @creatorLetterChanged=${this.creatorLetterSelected}
383
- >
384
- </sort-filter-bar>
385
- `;
386
- }
387
-
388
- private userChangedSort(
389
- e: CustomEvent<{
390
- selectedSort: SortField;
391
- sortDirection: SortDirection | null;
392
- }>
393
- ) {
394
- const { selectedSort, sortDirection } = e.detail;
395
- this.selectedSort = selectedSort;
396
- this.sortDirection = sortDirection;
397
-
398
- if ((this.currentPage ?? 1) > 1) {
399
- this.goToPage(1);
400
- }
401
- this.currentPage = 1;
402
- }
403
-
404
- private sendSortByAnalytics(prevSortDirection: SortDirection | null): void {
405
- const directionCleared = prevSortDirection && !this.sortDirection;
406
-
407
- this.analyticsHandler?.sendEventNoSampling({
408
- category: this.searchContext,
409
- action: analyticsActions.sortBy,
410
- label: `${this.selectedSort}${
411
- this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''
412
- }`,
413
- });
414
- }
415
-
416
- private selectedSortChanged(): void {
417
- if (this.selectedSort === 'relevance' || this.sortDirection === null) {
418
- this.sortParam = null;
419
- return;
420
- }
421
- const sortField = SortFieldToMetadataField[this.selectedSort];
422
-
423
- if (!sortField) return;
424
- this.sortParam = { field: sortField, direction: this.sortDirection };
425
- }
426
-
427
- private displayModeChanged(
428
- e: CustomEvent<{ displayMode: CollectionDisplayMode }>
429
- ) {
430
- this.displayMode = e.detail.displayMode;
431
-
432
- if (this.displayMode) {
433
- this.analyticsHandler?.sendEventNoSampling({
434
- category: this.searchContext,
435
- action: analyticsActions.displayMode,
436
- label: this.displayMode,
437
- });
438
- }
439
- }
440
-
441
- /** Send Analytics when sorting by title's first letter
442
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
443
- * */
444
- private sendFilterByTitleAnalytics(prevSelectedLetter: string | null): void {
445
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
446
- return;
447
- }
448
- const cleared = prevSelectedLetter && this.selectedTitleFilter === null;
449
-
450
- this.analyticsHandler?.sendEventNoSampling({
451
- category: this.searchContext,
452
- action: analyticsActions.filterByTitle,
453
- label: cleared
454
- ? `clear-${prevSelectedLetter}`
455
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
456
- });
457
- }
458
-
459
- private selectedTitleLetterChanged(): void {
460
- this.titleQuery = this.selectedTitleFilter
461
- ? `firstTitle:${this.selectedTitleFilter}`
462
- : undefined;
463
- }
464
-
465
- /** Send Analytics when filtering by creator's first letter
466
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
467
- * */
468
- private sendFilterByCreatorAnalytics(
469
- prevSelectedLetter: string | null
470
- ): void {
471
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
472
- return;
473
- }
474
- const cleared = prevSelectedLetter && this.selectedCreatorFilter === null;
475
-
476
- this.analyticsHandler?.sendEventNoSampling({
477
- category: this.searchContext,
478
- action: analyticsActions.filterByCreator,
479
- label: cleared
480
- ? `clear-${prevSelectedLetter}`
481
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
482
- });
483
- }
484
-
485
- private selectedCreatorLetterChanged(): void {
486
- this.creatorQuery = this.selectedCreatorFilter
487
- ? `firstCreator:${this.selectedCreatorFilter}`
488
- : undefined;
489
- }
490
-
491
- private titleLetterSelected(e: CustomEvent<{ selectedLetter: string }>) {
492
- this.selectedCreatorFilter = null;
493
- this.selectedTitleFilter = e.detail.selectedLetter;
494
- }
495
-
496
- private creatorLetterSelected(e: CustomEvent<{ selectedLetter: string }>) {
497
- this.selectedTitleFilter = null;
498
- this.selectedCreatorFilter = e.detail.selectedLetter;
499
- }
500
-
501
- private get facetDataLoading(): boolean {
502
- return (
503
- this.facetsLoading ||
504
- this.lendingFacetLoading ||
505
- this.fullYearAggregationLoading
506
- );
507
- }
508
-
509
- private get mobileFacetsTemplate() {
510
- return html`
511
- <div id="mobile-filter-collapse">
512
- <h1
513
- @click=${() => {
514
- this.isResizeToMobile = false;
515
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
516
- }}
517
- @keyup=${() => {
518
- this.isResizeToMobile = false;
519
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
520
- }}
521
- >
522
- <span class="collapser ${this.mobileFacetsVisible ? 'open' : ''}">
523
- ${chevronIcon}
524
- </span>
525
- Filters
526
- </h1>
527
- </div>
528
- `;
529
- }
530
-
531
- private get facetsTemplate() {
532
- return html`
533
- ${this.facetsLoading ? this.loadingTemplate : nothing}
534
- <collection-facets
535
- @facetsChanged=${this.facetsChanged}
536
- @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
537
- .searchService=${this.searchService}
538
- .searchType=${this.searchType}
539
- .aggregations=${this.aggregations}
540
- .fullYearsHistogramAggregation=${this.fullYearsHistogramAggregation}
541
- .previousSearchType=${this.previousSearchType}
542
- .minSelectedDate=${this.minSelectedDate}
543
- .maxSelectedDate=${this.maxSelectedDate}
544
- .selectedFacets=${this.selectedFacets}
545
- .collectionNameCache=${this.collectionNameCache}
546
- .languageCodeHandler=${this.languageCodeHandler}
547
- .showHistogramDatePicker=${this.showHistogramDatePicker}
548
- .fullQuery=${this.fullQuery}
549
- .modalManager=${this.modalManager}
550
- ?collapsableFacets=${this.mobileView}
551
- ?facetsLoading=${this.facetDataLoading}
552
- ?fullYearAggregationLoading=${this.fullYearAggregationLoading}
553
- .onFacetClick=${this.facetClickHandler}
554
- .analyticsHandler=${this.analyticsHandler}
555
- >
556
- </collection-facets>
557
- `;
558
- }
559
-
560
- private get loadingTemplate() {
561
- return html`
562
- <div class="loading-cover">
563
- <circular-activity-indicator></circular-activity-indicator>
564
- </div>
565
- `;
566
- }
567
-
568
- private get listHeaderTemplate() {
569
- return html`
570
- <div id="list-header">
571
- <tile-dispatcher
572
- .tileDisplayMode=${'list-header'}
573
- .resizeObserver=${this.resizeObserver}
574
- .sortParam=${this.sortParam}
575
- .mobileBreakpoint=${this.mobileBreakpoint}
576
- .loggedIn=${this.loggedIn}
577
- >
578
- </tile-dispatcher>
579
- </div>
580
- `;
581
- }
582
-
583
- private get queryDebuggingTemplate() {
584
- return html`
585
- <div>
586
- <ul>
587
- <li>Base Query: ${this.baseQuery}</li>
588
- <li>Facet Query: ${this.facetQuery}</li>
589
- <li>Sort Filter Query: ${this.sortFilterQueries}</li>
590
- <li>Date Range Query: ${this.dateRangeQueryClause}</li>
591
- <li>Sort: ${this.sortParam?.field} ${this.sortParam?.direction}</li>
592
- <li>Full Query: ${this.fullQuery}</li>
593
- </ul>
594
- </div>
595
- `;
596
- }
597
-
598
- private histogramDateRangeUpdated(
599
- e: CustomEvent<{
600
- minDate: string;
601
- maxDate: string;
602
- }>
603
- ) {
604
- const { minDate, maxDate } = e.detail;
605
- this.dateRangeQueryClause = `year:[${minDate} TO ${maxDate}]`;
606
-
607
- if (this.dateRangeQueryClause) {
608
- this.analyticsHandler?.sendEventNoSampling({
609
- category: this.searchContext,
610
- action: analyticsActions.histogramChanged,
611
- label: this.dateRangeQueryClause,
612
- });
613
- }
614
- }
615
-
616
- firstUpdated(): void {
617
- this.setupStateRestorationObserver();
618
- this.restoreState();
619
- }
620
-
621
- updated(changed: PropertyValues) {
622
- if (
623
- changed.has('displayMode') ||
624
- changed.has('baseNavigationUrl') ||
625
- changed.has('baseImageUrl') ||
626
- changed.has('loggedIn')
627
- ) {
628
- this.infiniteScroller?.reload();
629
- }
630
- if (changed.has('baseQuery')) {
631
- this.emitBaseQueryChanged();
632
- }
633
- if (changed.has('currentPage') || changed.has('displayMode')) {
634
- this.persistState();
635
- }
636
- if (
637
- changed.has('baseQuery') ||
638
- changed.has('titleQuery') ||
639
- changed.has('creatorQuery') ||
640
- changed.has('dateRangeQueryClause') ||
641
- changed.has('sortParam') ||
642
- changed.has('selectedFacets') ||
643
- changed.has('searchService')
644
- ) {
645
- this.handleQueryChange();
646
- }
647
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
648
- const prevSortDirection = changed.get('sortDirection') as SortDirection;
649
- this.sendSortByAnalytics(prevSortDirection);
650
- this.selectedSortChanged();
651
- }
652
- if (changed.has('selectedTitleFilter')) {
653
- this.sendFilterByTitleAnalytics(
654
- changed.get('selectedTitleFilter') as string
655
- );
656
- this.selectedTitleLetterChanged();
657
- }
658
- if (changed.has('selectedCreatorFilter')) {
659
- this.sendFilterByCreatorAnalytics(
660
- changed.get('selectedCreatorFilter') as string
661
- );
662
- this.selectedCreatorLetterChanged();
663
- }
664
- if (changed.has('pagesToRender')) {
665
- if (!this.endOfDataReached && this.infiniteScroller) {
666
- this.infiniteScroller.itemCount = this.estimatedTileCount;
667
- }
668
- }
669
- if (changed.has('resizeObserver')) {
670
- const oldObserver = changed.get(
671
- 'resizeObserver'
672
- ) as SharedResizeObserverInterface;
673
- if (oldObserver) this.disconnectResizeObserver(oldObserver);
674
- this.setupResizeObserver();
675
- }
676
- }
677
-
678
- disconnectedCallback(): void {
679
- if (this.resizeObserver) {
680
- this.disconnectResizeObserver(this.resizeObserver);
681
- }
682
- if (this.boundNavigationHandler) {
683
- window.removeEventListener('popstate', this.boundNavigationHandler);
684
- }
685
- }
686
-
687
- handleResize(entry: ResizeObserverEntry): void {
688
- const previousView = this.mobileView;
689
- if (entry.target === this.contentContainer) {
690
- this.mobileView = entry.contentRect.width < this.mobileBreakpoint;
691
- // If changing from desktop to mobile disable transition
692
- if (this.mobileView && !previousView) {
693
- this.isResizeToMobile = true;
694
- }
695
- }
696
- }
697
-
698
- private emitBaseQueryChanged() {
699
- this.dispatchEvent(
700
- new CustomEvent<{ baseQuery?: string }>('baseQueryChanged', {
701
- detail: {
702
- baseQuery: this.baseQuery,
703
- },
704
- })
705
- );
706
- }
707
-
708
- private disconnectResizeObserver(
709
- resizeObserver: SharedResizeObserverInterface
710
- ) {
711
- resizeObserver.removeObserver({
712
- target: this.contentContainer,
713
- handler: this,
714
- });
715
- }
716
-
717
- private setupResizeObserver() {
718
- if (!this.resizeObserver) return;
719
- this.resizeObserver.addObserver({
720
- target: this.contentContainer,
721
- handler: this,
722
- });
723
- }
724
-
725
- /**
726
- * When the visible cells change from the infinite scroller, we want to emit
727
- * which page is currently visible so the consumer can update its UI or the URL
728
- *
729
- * @param e
730
- * @returns
731
- */
732
- private visibleCellsChanged(
733
- e: CustomEvent<{ visibleCellIndices: number[] }>
734
- ) {
735
- if (this.isScrollingToCell) return;
736
- const { visibleCellIndices } = e.detail;
737
- if (visibleCellIndices.length === 0) return;
738
- const lastVisibleCellIndex =
739
- visibleCellIndices[visibleCellIndices.length - 1];
740
- const lastVisibleCellPage =
741
- Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
742
- if (this.currentPage !== lastVisibleCellPage) {
743
- this.currentPage = lastVisibleCellPage;
744
- }
745
- const event = new CustomEvent('visiblePageChanged', {
746
- detail: {
747
- pageNumber: lastVisibleCellPage,
748
- },
749
- });
750
- this.dispatchEvent(event);
751
- }
752
-
753
- // we only want to scroll on the very first query change
754
- // so this keeps track of whether we've already set the initial query
755
- private initialQueryChangeHappened = false;
756
-
757
- private historyPopOccurred = false;
758
-
759
- // this lets us store the query key so we know if it's actually changed or not
760
- private previousQueryKey?: string;
761
-
762
- private async handleQueryChange() {
763
- // only reset if the query has actually changed
764
- if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
765
- return;
766
- this.previousQueryKey = this.pageFetchQueryKey;
767
-
768
- this.dataSource = {};
769
- this.pageFetchesInProgress = {};
770
- this.endOfDataReached = false;
771
- this.pagesToRender = this.initialPageNumber;
772
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
773
- this.scrollToPage(this.initialPageNumber);
774
- }
775
- this.initialQueryChangeHappened = true;
776
- // if the query changed as part of a window.history pop event, we don't want to
777
- // persist the state because it overwrites the forward history
778
- if (!this.historyPopOccurred) {
779
- this.persistState();
780
- this.historyPopOccurred = false;
781
- }
782
-
783
- // Ensure lending aggregations don't carry over to non-metadata searches
784
- if (this.searchType !== SearchType.METADATA) {
785
- delete this.aggregations?.lending;
786
- }
787
-
788
- await Promise.all([
789
- this.doInitialPageFetch(),
790
- this.fetchFacets(),
791
- this.fetchLendingFacet(),
792
- this.fetchFullYearHistogram(),
793
- ]);
794
- }
795
-
796
- private setupStateRestorationObserver() {
797
- if (this.boundNavigationHandler) return;
798
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
799
- // when the user navigates back, we want to update the UI to match the URL
800
- window.addEventListener('popstate', this.boundNavigationHandler);
801
- }
802
-
803
- private boundNavigationHandler?: () => void;
804
-
805
- private historyNavigationHandler() {
806
- this.historyPopOccurred = true;
807
- this.restoreState();
808
- }
809
-
810
- private restoreState() {
811
- const restorationState = this.restorationStateHandler.getRestorationState();
812
- this.displayMode = restorationState.displayMode;
813
- this.selectedSort = restorationState.selectedSort ?? SortField.relevance;
814
- this.sortDirection = restorationState.sortDirection ?? null;
815
- this.selectedTitleFilter = restorationState.selectedTitleFilter ?? null;
816
- this.selectedCreatorFilter = restorationState.selectedCreatorFilter ?? null;
817
- this.selectedFacets = restorationState.selectedFacets;
818
- this.baseQuery = restorationState.baseQuery;
819
- this.titleQuery = restorationState.titleQuery;
820
- this.creatorQuery = restorationState.creatorQuery;
821
- this.dateRangeQueryClause = restorationState.dateRangeQueryClause;
822
- this.sortParam = restorationState.sortParam ?? null;
823
- this.currentPage = restorationState.currentPage ?? 1;
824
- this.minSelectedDate = restorationState.minSelectedDate;
825
- this.maxSelectedDate = restorationState.maxSelectedDate;
826
- if (this.currentPage > 1) {
827
- this.goToPage(this.currentPage);
828
- }
829
- }
830
-
831
- private persistState() {
832
- const restorationState: RestorationState = {
833
- displayMode: this.displayMode,
834
- sortParam: this.sortParam ?? undefined,
835
- selectedSort: this.selectedSort,
836
- sortDirection: this.sortDirection ?? undefined,
837
- selectedFacets: this.selectedFacets ?? defaultSelectedFacets,
838
- baseQuery: this.baseQuery,
839
- currentPage: this.currentPage,
840
- dateRangeQueryClause: this.dateRangeQueryClause,
841
- titleQuery: this.titleQuery,
842
- creatorQuery: this.creatorQuery,
843
- minSelectedDate: this.minSelectedDate,
844
- maxSelectedDate: this.maxSelectedDate,
845
- selectedTitleFilter: this.selectedTitleFilter ?? undefined,
846
- selectedCreatorFilter: this.selectedCreatorFilter ?? undefined,
847
- };
848
- this.restorationStateHandler.persistState(restorationState);
849
- }
850
-
851
- private async doInitialPageFetch() {
852
- this.searchResultsLoading = true;
853
- await this.fetchPage(this.initialPageNumber);
854
- this.searchResultsLoading = false;
855
- }
856
-
857
- private get fullQuery(): string | undefined {
858
- let { fullQueryWithoutDate } = this;
859
- const { dateRangeQueryClause } = this;
860
- if (dateRangeQueryClause) {
861
- fullQueryWithoutDate += ` AND ${dateRangeQueryClause}`;
862
- }
863
- return fullQueryWithoutDate;
864
- }
865
-
866
- private get fullQueryWithoutDate(): string | undefined {
867
- if (!this.baseQuery) return undefined;
868
- let fullQuery = this.baseQuery;
869
- const { facetQuery, sortFilterQueries } = this;
870
- if (facetQuery) {
871
- fullQuery += ` AND ${facetQuery}`;
872
- }
873
- if (sortFilterQueries) {
874
- fullQuery += ` AND ${sortFilterQueries}`;
875
- }
876
- return fullQuery;
877
- }
878
-
879
- /**
880
- * Generates a query string for the given facets
881
- *
882
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
883
- */
884
- private get facetQuery(): string | undefined {
885
- if (!this.selectedFacets) return undefined;
886
- const facetQuery = [];
887
- for (const [facetName, facetValues] of Object.entries(
888
- this.selectedFacets
889
- )) {
890
- const facetEntries = Object.entries(facetValues);
891
- const facetQueryName =
892
- facetName === 'lending' ? 'lending___status' : facetName;
893
- // eslint-disable-next-line no-continue
894
- if (facetEntries.length === 0) continue;
895
- const facetValuesArray: string[] = [];
896
- for (const [key, facetData] of facetEntries) {
897
- const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
898
-
899
- if (facetName === 'language') {
900
- const languages =
901
- this.languageCodeHandler.getCodeArrayFromCodeString(key);
902
- for (const language of languages) {
903
- facetValuesArray.push(`${plusMinusPrefix}"${language}"`);
904
- }
905
- } else {
906
- facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
907
- }
908
- }
909
- const valueQuery = facetValuesArray.join(` OR `);
910
- facetQuery.push(`${facetQueryName}:(${valueQuery})`);
911
- }
912
- return facetQuery.length > 0 ? `(${facetQuery.join(' AND ')})` : undefined;
913
- }
914
-
915
- facetsChanged(e: CustomEvent<SelectedFacets>) {
916
- this.selectedFacets = e.detail;
917
- }
918
-
919
- facetClickHandler(
920
- name: FacetOption,
921
- facetSelected: boolean,
922
- negative: boolean
923
- ): void {
924
- if (negative) {
925
- this.analyticsHandler?.sendEventNoSampling({
926
- category: this.searchContext,
927
- action: facetSelected
928
- ? analyticsActions.facetNegativeSelected
929
- : analyticsActions.facetNegativeDeselected,
930
- label: name,
931
- });
932
- } else {
933
- this.analyticsHandler?.sendEventNoSampling({
934
- category: this.searchContext,
935
- action: facetSelected
936
- ? analyticsActions.facetSelected
937
- : analyticsActions.facetDeselected,
938
- label: name,
939
- });
940
- }
941
- }
942
-
943
- private async fetchFacets() {
944
- if (!this.fullQuery) return;
945
-
946
- const params: SearchParams = {
947
- query: this.fullQuery,
948
- rows: 0,
949
- // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
950
- // The default aggregations for the search_results page type should be what we need here.
951
- };
952
-
953
- this.facetsLoading = true;
954
- this.previousSearchType = this.searchType;
955
- const results = await this.searchService?.search(params, this.searchType);
956
- this.facetsLoading = false;
957
-
958
- this.aggregations = {
959
- ...this.aggregations,
960
- ...results?.success?.response.aggregations,
961
- };
962
- }
963
-
964
- private async fetchLendingFacet() {
965
- // Only retrieve lending facet for metadata searches
966
- if (this.searchType !== SearchType.METADATA) return;
967
- if (!this.fullQuery) return;
968
-
969
- const params: SearchParams = {
970
- query: this.fullQuery,
971
- rows: 0,
972
- aggregations: {
973
- simpleParams: ['lending___status'],
974
- },
975
- aggregationsSize: 10, // Larger size to ensure we get all possible statuses
976
- };
977
-
978
- this.lendingFacetLoading = true;
979
- const results = await this.searchService?.search(params, this.searchType);
980
- this.lendingFacetLoading = false;
981
-
982
- this.aggregations = {
983
- ...this.aggregations,
984
- ...results?.success?.response.aggregations,
985
- };
986
- }
987
-
988
- /**
989
- * If we haven't changed the query, we don't need to fetch the full year histogram
990
- *
991
- * @private
992
- * @type {string}
993
- * @memberof CollectionBrowser
994
- */
995
- private previousFullQueryNoDate?: string;
996
-
997
- /**
998
- * The query key is a string that uniquely identifies the current query
999
- * without the date range.
1000
- *
1001
- * If this doesn't change, we don't need to re-fetch the histogram date range
1002
- */
1003
- private get fullQueryNoDateKey() {
1004
- return `${this.fullQueryWithoutDate}-${this.searchType}-${this.sortParam?.field}-${this.sortParam?.direction}`;
1005
- }
1006
-
1007
- /**
1008
- * This method is similar to fetching the facets above,
1009
- * but only fetching the year histogram. There is a subtle difference
1010
- * in how you have to fetch the year histogram where you can't use the
1011
- * advanced JSON syntax like the other aggregations. It's a special
1012
- * case that @ximm put it place.
1013
- */
1014
- private async fetchFullYearHistogram(): Promise<void> {
1015
- const { fullQueryNoDateKey } = this;
1016
- if (
1017
- !this.fullQueryWithoutDate ||
1018
- fullQueryNoDateKey === this.previousFullQueryNoDate
1019
- )
1020
- return;
1021
- this.previousFullQueryNoDate = fullQueryNoDateKey;
1022
-
1023
- const aggregations = {
1024
- simpleParams: ['year'],
1025
- };
1026
-
1027
- const params = {
1028
- query: this.fullQueryWithoutDate,
1029
- aggregations,
1030
- rows: 0,
1031
- };
1032
-
1033
- this.fullYearAggregationLoading = true;
1034
- const results = await this.searchService?.search(params, this.searchType);
1035
- this.fullYearAggregationLoading = false;
1036
-
1037
- this.fullYearsHistogramAggregation =
1038
- results?.success?.response?.aggregations?.year_histogram;
1039
- }
1040
-
1041
- private scrollToPage(pageNumber: number) {
1042
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1043
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1044
- // then scrolls to the cell
1045
- setTimeout(() => {
1046
- this.isScrollingToCell = true;
1047
- this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
1048
- // This timeout is to give the scroll animation time to finish
1049
- // then updating the infinite scroller once we're done scrolling
1050
- // There's no scroll animation completion callback so we're
1051
- // giving it 0.5s to finish.
1052
- setTimeout(() => {
1053
- this.isScrollingToCell = false;
1054
- this.infiniteScroller.reload();
1055
- }, 500);
1056
- }, 0);
1057
- }
1058
-
1059
- /**
1060
- * The query key is a string that uniquely identifies the current query
1061
- *
1062
- * This lets us keep track of queries so we don't persist data that's
1063
- * no longer relevant.
1064
- */
1065
- private get pageFetchQueryKey() {
1066
- return `${this.fullQuery}-${this.searchType}-${this.sortParam?.field}-${this.sortParam?.direction}`;
1067
- }
1068
-
1069
- // this maps the query to the pages being fetched for that query
1070
- private pageFetchesInProgress: Record<string, Set<number>> = {};
1071
-
1072
- async fetchPage(pageNumber: number) {
1073
- if (!this.fullQuery) return;
1074
-
1075
- // if we already have data, don't fetch again
1076
- if (this.dataSource[pageNumber]) return;
1077
-
1078
- if (this.endOfDataReached) return;
1079
-
1080
- // if a fetch is already in progress for this query and page, don't fetch again
1081
- const { pageFetchQueryKey } = this;
1082
- const pageFetches =
1083
- this.pageFetchesInProgress[pageFetchQueryKey] ?? new Set();
1084
- if (pageFetches.has(pageNumber)) return;
1085
- pageFetches.add(pageNumber);
1086
- this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1087
-
1088
- const sortParams = this.sortParam ? [this.sortParam] : [];
1089
- const params: SearchParams = {
1090
- query: this.fullQuery,
1091
- fields: [
1092
- 'addeddate',
1093
- 'avg_rating',
1094
- 'collections_raw',
1095
- 'creator',
1096
- 'date',
1097
- 'description',
1098
- 'downloads',
1099
- 'identifier',
1100
- 'issue',
1101
- 'item_count',
1102
- 'mediatype',
1103
- 'num_favorites',
1104
- 'num_reviews',
1105
- 'publicdate',
1106
- 'reviewdate',
1107
- 'source',
1108
- 'subject', // topic
1109
- 'title',
1110
- 'volume',
1111
- ],
1112
- page: pageNumber,
1113
- rows: this.pageSize,
1114
- sort: sortParams,
1115
- aggregations: { omit: true },
1116
- };
1117
- const searchResponse = await this.searchService?.search(
1118
- params,
1119
- this.searchType
1120
- );
1121
- const success = searchResponse?.success;
1122
-
1123
- if (!success) return;
1124
-
1125
- this.totalResults = success.response.totalResults;
1126
-
1127
- // this is checking to see if the query has changed since the data was fetched
1128
- // if so, we just want to discard the data since there should be a new query
1129
- // right behind it
1130
- const searchQuery = success.request.clientParameters.user_query;
1131
- const searchSort = success.request.clientParameters.sort;
1132
- let sortChanged = false;
1133
- if (!searchSort || searchSort.length === 0) {
1134
- // if we went from no sort to sort, the sort has changed
1135
- if (this.sortParam) {
1136
- sortChanged = true;
1137
- }
1138
- } else {
1139
- // check if the sort has changed
1140
- for (const sortType of searchSort) {
1141
- const [field, direction] = sortType.split(':');
1142
- if (
1143
- field !== this.sortParam?.field ||
1144
- direction !== this.sortParam?.direction
1145
- ) {
1146
- sortChanged = true;
1147
- break;
1148
- }
1149
- }
1150
- }
1151
- const queryChangedSinceFetch =
1152
- searchQuery !== this.fullQuery || sortChanged;
1153
- if (queryChangedSinceFetch) return;
1154
-
1155
- const { results } = success.response;
1156
- if (results && results.length > 0) {
1157
- this.preloadCollectionNames(results);
1158
- this.updateDataSource(pageNumber, results);
1159
- }
1160
- if (results.length < this.pageSize) {
1161
- this.endOfDataReached = true;
1162
- // this updates the infinite scroller to show the actual size
1163
- if (this.infiniteScroller) {
1164
- this.infiniteScroller.itemCount = this.actualTileCount;
1165
- }
1166
- }
1167
- this.pageFetchesInProgress[pageFetchQueryKey]?.delete(pageNumber);
1168
- this.searchResultsLoading = false;
1169
- }
1170
-
1171
- private preloadCollectionNames(results: SearchResult[]) {
1172
- const collectionIds = results
1173
- .map(result => result.collection?.values)
1174
- .flat();
1175
- const collectionIdsArray = Array.from(new Set(collectionIds)) as string[];
1176
- this.collectionNameCache?.preloadIdentifiers(collectionIdsArray);
1177
- }
1178
-
1179
- /**
1180
- * This is useful for determining whether we need to reload the scroller.
1181
- *
1182
- * When the fetch completes, we need to reload the scroller if the cells for that
1183
- * page are visible, but if the page is not currenlty visible, we don't need to reload
1184
- */
1185
- private get currentVisiblePageNumbers(): number[] {
1186
- const visibleCells = this.infiniteScroller.getVisibleCellIndices();
1187
- const visiblePages = new Set<number>();
1188
- visibleCells.forEach(cellIndex => {
1189
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1190
- visiblePages.add(visiblePage);
1191
- });
1192
- return Array.from(visiblePages);
1193
- }
1194
-
1195
- /**
1196
- * Update the datasource from the fetch response
1197
- *
1198
- * @param pageNumber
1199
- * @param results
1200
- */
1201
- private updateDataSource(pageNumber: number, results: SearchResult[]) {
1202
- // copy our existing datasource so when we set it below, it gets set
1203
- // instead of modifying the existing dataSource since object changes
1204
- // don't trigger a re-render
1205
- const datasource = { ...this.dataSource };
1206
- const tiles: TileModel[] = [];
1207
- results?.forEach(result => {
1208
- if (!result.identifier) return;
1209
-
1210
- let loginRequired = false;
1211
- let contentWarning = false;
1212
- // Check if item and item in "modifying" collection, setting above flags
1213
- if (
1214
- result.collection?.values.length &&
1215
- result.mediatype?.value !== 'collection'
1216
- ) {
1217
- for (const collection of result.collection?.values ?? []) {
1218
- if (collection === 'loggedin') {
1219
- loginRequired = true;
1220
- if (contentWarning) break;
1221
- }
1222
- if (collection === 'no-preview') {
1223
- contentWarning = true;
1224
- if (loginRequired) break;
1225
- }
1226
- }
1227
- }
1228
-
1229
- tiles.push({
1230
- // TODO the commented items are not currently being returned by the PPS and
1231
- // we will need to have them added to the PPS hit schemas where appropriate
1232
-
1233
- // averageRating: result.avg_rating?.value,
1234
- collections: result.collection?.values ?? [],
1235
- commentCount: result.num_reviews?.value ?? 0,
1236
- creator: result.creator?.value,
1237
- creators: result.creator?.values ?? [],
1238
- // dateAdded: result.addeddate?.value,
1239
- dateArchived: result.publicdate?.value,
1240
- datePublished: result.date?.value,
1241
- dateReviewed: result.reviewdate?.value,
1242
- description: result.description?.value,
1243
- favCount: result.num_favorites?.value ?? 0,
1244
- identifier: result.identifier,
1245
- // issue: result.issue?.value,
1246
- itemCount: 0, // result.item_count?.value ?? 0,
1247
- mediatype: result.mediatype?.value ?? 'data',
1248
- snippets: result.highlight?.values ?? [],
1249
- // source: result.source?.value,
1250
- subjects: result.subject?.values ?? [],
1251
- title: this.etreeTitle(
1252
- result.title?.value,
1253
- result.mediatype?.value,
1254
- result.collection?.values
1255
- ),
1256
- volume: result.volume?.value,
1257
- viewCount: result.downloads?.value ?? 0,
1258
- loginRequired,
1259
- contentWarning,
1260
- });
1261
- });
1262
- datasource[pageNumber] = tiles;
1263
- this.dataSource = datasource;
1264
- const visiblePages = this.currentVisiblePageNumbers;
1265
- const needsReload = visiblePages.includes(pageNumber);
1266
- if (needsReload) {
1267
- this.infiniteScroller.reload();
1268
- }
1269
- }
1270
-
1271
- /*
1272
- * Convert etree titles
1273
- * "[Creator] Live at [Place] on [Date]" => "[Date]: [Place]"
1274
- *
1275
- * Todo: Check collection(s) for etree, need to get as array.
1276
- * Current search-service only returns first collection as string.
1277
- */
1278
- private etreeTitle(
1279
- title: string | undefined,
1280
- mediatype: string | undefined,
1281
- collections: string[] | undefined
1282
- ): string {
1283
- if (mediatype === 'etree' || collections?.includes('etree')) {
1284
- const regex = /^(.*) Live at (.*) on (\d\d\d\d-\d\d-\d\d)$/;
1285
- const newTitle = title?.replace(regex, '$3: $2');
1286
- if (newTitle) {
1287
- return `${newTitle}`;
1288
- }
1289
- }
1290
- return title ?? '';
1291
- }
1292
-
1293
- /**
1294
- * Callback when a result is selected
1295
- */
1296
- resultSelected(event: CustomEvent<TileModel>): void {
1297
- this.analyticsHandler?.sendEventNoSampling({
1298
- category: this.searchContext,
1299
- action: analyticsActions.resultSelected,
1300
- label: event.detail.mediatype,
1301
- });
1302
-
1303
- this.analyticsHandler?.sendEventNoSampling({
1304
- category: this.searchContext,
1305
- action: analyticsActions.resultSelected,
1306
- label: `page-${this.currentPage}`,
1307
- });
1308
- }
1309
-
1310
- cellForIndex(index: number): TemplateResult | undefined {
1311
- const model = this.tileModelAtCellIndex(index);
1312
- if (!model) return undefined;
1313
-
1314
- return html`
1315
- <tile-dispatcher
1316
- .baseNavigationUrl=${this.baseNavigationUrl}
1317
- .baseImageUrl=${this.baseImageUrl}
1318
- .model=${model}
1319
- .tileDisplayMode=${this.displayMode}
1320
- .resizeObserver=${this.resizeObserver}
1321
- .collectionNameCache=${this.collectionNameCache}
1322
- .sortParam=${this.sortParam}
1323
- .mobileBreakpoint=${this.mobileBreakpoint}
1324
- .loggedIn=${this.loggedIn}
1325
- @resultSelected=${(e: CustomEvent) => this.resultSelected(e)}
1326
- >
1327
- </tile-dispatcher>
1328
- `;
1329
- }
1330
-
1331
- /**
1332
- * When the user scrolls near to the bottom of the page, fetch the next page
1333
- * increase the number of pages to render and start fetching data for the new page
1334
- */
1335
- private scrollThresholdReached() {
1336
- this.pagesToRender += 1;
1337
- this.fetchPage(this.pagesToRender);
1338
- }
1339
-
1340
- static styles = css`
1341
- :host {
1342
- display: block;
1343
- }
1344
-
1345
- /**
1346
- * When page width resizes from desktop to mobile, use this class to
1347
- * disable expand/collapse transition when loading.
1348
- */
1349
- .preload * {
1350
- transition: none !important;
1351
- -webkit-transition: none !important;
1352
- -moz-transition: none !important;
1353
- -ms-transition: none !important;
1354
- -o-transition: none !important;
1355
- }
1356
-
1357
- #content-container {
1358
- display: flex;
1359
- }
1360
-
1361
- .collapser {
1362
- display: inline-block;
1363
- }
1364
-
1365
- .collapser svg {
1366
- width: 10px;
1367
- height: 10px;
1368
- transition: transform 0.2s ease-out;
1369
- }
1370
-
1371
- .collapser.open svg {
1372
- transform: rotate(90deg);
1373
- }
1374
-
1375
- #mobile-filter-collapse h1 {
1376
- cursor: pointer;
1377
- }
1378
-
1379
- #content-container.mobile {
1380
- display: block;
1381
- }
1382
-
1383
- .column {
1384
- padding-top: 2rem;
1385
- }
1386
-
1387
- #right-column {
1388
- flex: 1;
1389
- position: relative;
1390
- border-left: 1px solid rgb(232, 232, 232);
1391
- padding-left: 1rem;
1392
- }
1393
-
1394
- .mobile #right-column {
1395
- border-left: none;
1396
- padding: 0;
1397
- }
1398
-
1399
- #left-column {
1400
- width: 18rem;
1401
- min-width: 18rem; /* Prevents Safari from shrinking col at first draw */
1402
- padding-right: 12px;
1403
- padding-right: 1rem;
1404
- }
1405
-
1406
- .desktop #left-column::-webkit-scrollbar {
1407
- display: none;
1408
- }
1409
-
1410
- .mobile #left-column {
1411
- width: 100%;
1412
- padding: 0;
1413
- }
1414
-
1415
- .desktop #left-column {
1416
- top: 0;
1417
- position: sticky;
1418
- max-height: 100vh;
1419
- overflow: scroll;
1420
- -ms-overflow-style: none; /* hide scrollbar IE and Edge */
1421
- scrollbar-width: none; /* hide scrollbar Firefox */
1422
- }
1423
-
1424
- #mobile-header-container {
1425
- display: flex;
1426
- justify-content: space-between;
1427
- }
1428
-
1429
- #facets-container {
1430
- position: relative;
1431
- max-height: 0;
1432
- transition: max-height 0.2s ease-in-out;
1433
- z-index: 1;
1434
- padding-bottom: 2rem;
1435
- }
1436
-
1437
- .mobile #facets-container {
1438
- overflow: hidden;
1439
- padding-bottom: 0;
1440
- }
1441
-
1442
- #facets-container.expanded {
1443
- max-height: 2000px;
1444
- }
1445
-
1446
- #results-total {
1447
- display: flex;
1448
- align-items: center;
1449
- margin-bottom: 5rem;
1450
- }
1451
-
1452
- .mobile #results-total {
1453
- margin-bottom: 0;
1454
- }
1455
-
1456
- #big-results-count {
1457
- font-size: 2.4rem;
1458
- font-weight: 500;
1459
- margin-right: 5px;
1460
- }
1461
-
1462
- #big-results-label {
1463
- font-size: 1rem;
1464
- font-weight: 200;
1465
- text-transform: uppercase;
1466
- }
1467
-
1468
- #list-header {
1469
- max-height: 4.2rem;
1470
- }
1471
-
1472
- .loading-cover {
1473
- position: absolute;
1474
- top: 0;
1475
- left: 0;
1476
- width: 100%;
1477
- height: 100%;
1478
- display: flex;
1479
- justify-content: center;
1480
- z-index: 1;
1481
- padding-top: 50px;
1482
- }
1483
-
1484
- circular-activity-indicator {
1485
- width: 30px;
1486
- height: 30px;
1487
- }
1488
-
1489
- sort-filter-bar {
1490
- display: block;
1491
- margin-bottom: 4rem;
1492
- }
1493
-
1494
- infinite-scroller {
1495
- display: block;
1496
- --infiniteScrollerRowGap: var(--collectionBrowserRowGap, 1.7rem);
1497
- --infiniteScrollerColGap: var(--collectionBrowserColGap, 1.7rem);
1498
- }
1499
-
1500
- infinite-scroller.list-compact {
1501
- --infiniteScrollerCellMinWidth: var(
1502
- --collectionBrowserCellMinWidth,
1503
- 100%
1504
- );
1505
- --infiniteScrollerCellMinHeight: 34px; /* override infinite scroller component */
1506
- --infiniteScrollerCellMaxHeight: 56px;
1507
- --infiniteScrollerRowGap: 0px;
1508
- }
1509
-
1510
- infinite-scroller.list-detail {
1511
- --infiniteScrollerCellMinWidth: var(
1512
- --collectionBrowserCellMinWidth,
1513
- 100%
1514
- );
1515
- --infiniteScrollerCellMinHeight: var(
1516
- --collectionBrowserCellMinHeight,
1517
- 5rem
1518
- );
1519
- /*
1520
- 30px in spec, compensating for a -4px margin
1521
- to align title with top of item image
1522
- src/tiles/list/tile-list.ts
1523
- */
1524
- --infiniteScrollerRowGap: 34px;
1525
- }
1526
-
1527
- .mobile infinite-scroller.list-detail {
1528
- --infiniteScrollerRowGap: 24px;
1529
- }
1530
-
1531
- infinite-scroller.grid {
1532
- --infiniteScrollerCellMinWidth: var(
1533
- --collectionBrowserCellMinWidth,
1534
- 18rem
1535
- );
1536
- --infiniteScrollerCellMaxWidth: var(--collectionBrowserCellMaxWidth, 1fr);
1537
- --infiniteScrollerCellMinHeight: var(
1538
- --collectionBrowserCellMinHeight,
1539
- 29rem
1540
- );
1541
- --infiniteScrollerCellMaxHeight: var(
1542
- --collectionBrowserCellMaxHeight,
1543
- 29rem
1544
- );
1545
- }
1546
- `;
1547
- }
1
+ /* eslint-disable import/no-duplicates */
2
+ import {
3
+ html,
4
+ css,
5
+ LitElement,
6
+ PropertyValues,
7
+ TemplateResult,
8
+ nothing,
9
+ } from 'lit';
10
+ import { customElement, property, query, state } from 'lit/decorators.js';
11
+ import { ifDefined } from 'lit/directives/if-defined.js';
12
+
13
+ import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
14
+ import type {
15
+ InfiniteScroller,
16
+ InfiniteScrollerCellProviderInterface,
17
+ } from '@internetarchive/infinite-scroller';
18
+ import {
19
+ Aggregation,
20
+ SearchParams,
21
+ SearchResult,
22
+ SearchServiceInterface,
23
+ SearchType,
24
+ SortDirection,
25
+ SortParam,
26
+ } from '@internetarchive/search-service';
27
+ import type {
28
+ SharedResizeObserverInterface,
29
+ SharedResizeObserverResizeHandlerInterface,
30
+ } from '@internetarchive/shared-resize-observer';
31
+ import '@internetarchive/infinite-scroller';
32
+ import type { CollectionNameCacheInterface } from '@internetarchive/collection-name-cache';
33
+ import type { ModalManagerInterface } from '@internetarchive/modal-manager';
34
+ import './tiles/tile-dispatcher';
35
+ import './tiles/collection-browser-loading-tile';
36
+ import './sort-filter-bar/sort-filter-bar';
37
+ import './collection-facets';
38
+ import './circular-activity-indicator';
39
+ import './sort-filter-bar/sort-filter-bar';
40
+ import {
41
+ SelectedFacets,
42
+ SortField,
43
+ SortFieldToMetadataField,
44
+ CollectionBrowserContext,
45
+ defaultSelectedFacets,
46
+ TileModel,
47
+ CollectionDisplayMode,
48
+ FacetOption,
49
+ } from './models';
50
+ import {
51
+ RestorationStateHandlerInterface,
52
+ RestorationStateHandler,
53
+ RestorationState,
54
+ } from './restoration-state-handler';
55
+ import chevronIcon from './assets/img/icons/chevron';
56
+ import { LanguageCodeHandler } from './language-code-handler/language-code-handler';
57
+ import type { PlaceholderType } from './empty-placeholder';
58
+ import './empty-placeholder';
59
+
60
+ import {
61
+ analyticsActions,
62
+ analyticsCategories,
63
+ } from './utils/analytics-events';
64
+
65
+ @customElement('collection-browser')
66
+ export class CollectionBrowser
67
+ extends LitElement
68
+ implements
69
+ InfiniteScrollerCellProviderInterface,
70
+ SharedResizeObserverResizeHandlerInterface
71
+ {
72
+ @property({ type: String }) baseNavigationUrl?: string;
73
+
74
+ @property({ type: String }) baseImageUrl: string = 'https://archive.org';
75
+
76
+ @property({ type: Object }) searchService?: SearchServiceInterface;
77
+
78
+ @property({ type: String }) searchType: SearchType = SearchType.METADATA;
79
+
80
+ @property({ type: String }) baseQuery?: string;
81
+
82
+ @property({ type: String }) displayMode?: CollectionDisplayMode;
83
+
84
+ @property({ type: Object }) sortParam: SortParam | null = null;
85
+
86
+ @property({ type: String }) selectedSort: SortField = SortField.relevance;
87
+
88
+ @property({ type: String }) selectedTitleFilter: string | null = null;
89
+
90
+ @property({ type: String }) selectedCreatorFilter: string | null = null;
91
+
92
+ @property({ type: String }) sortDirection: SortDirection | null = null;
93
+
94
+ @property({ type: String }) dateRangeQueryClause?: string;
95
+
96
+ @property({ type: Number }) pageSize = 50;
97
+
98
+ @property({ type: Object }) resizeObserver?: SharedResizeObserverInterface;
99
+
100
+ @property({ type: String }) titleQuery?: string;
101
+
102
+ @property({ type: String }) creatorQuery?: string;
103
+
104
+ @property({ type: Number }) currentPage?: number;
105
+
106
+ @property({ type: String }) minSelectedDate?: string;
107
+
108
+ @property({ type: String }) maxSelectedDate?: string;
109
+
110
+ @property({ type: Object }) selectedFacets?: SelectedFacets;
111
+
112
+ @property({ type: Boolean }) showHistogramDatePicker = false;
113
+
114
+ /** describes where this component is being used */
115
+ @property({ type: String, reflect: true }) searchContext: string =
116
+ analyticsCategories.default;
117
+
118
+ @property({ type: Object })
119
+ collectionNameCache?: CollectionNameCacheInterface;
120
+
121
+ @property({ type: String }) pageContext: CollectionBrowserContext = 'search';
122
+
123
+ @property({ type: Object })
124
+ restorationStateHandler: RestorationStateHandlerInterface = new RestorationStateHandler(
125
+ {
126
+ context: this.pageContext,
127
+ }
128
+ );
129
+
130
+ @property({ type: Number }) mobileBreakpoint = 600;
131
+
132
+ @property({ type: Boolean }) loggedIn = false;
133
+
134
+ @property({ type: Object }) modalManager?: ModalManagerInterface = undefined;
135
+
136
+ /**
137
+ * If item management UI active
138
+ */
139
+ @property({ type: Boolean }) isManageView = false;
140
+
141
+ /**
142
+ * The page that the consumer wants to load.
143
+ */
144
+ private initialPageNumber = 1;
145
+
146
+ /**
147
+ * This the the number of pages that we want to show.
148
+ *
149
+ * The data isn't necessarily loaded for all of the pages, but this lets us
150
+ * know how many cells we should render.
151
+ */
152
+ @state() private pagesToRender = this.initialPageNumber;
153
+
154
+ @state() private searchResultsLoading = false;
155
+
156
+ @state() private facetsLoading = false;
157
+
158
+ @state() private lendingFacetLoading = false;
159
+
160
+ @state() private fullYearAggregationLoading = false;
161
+
162
+ @state() private aggregations?: Record<string, Aggregation>;
163
+
164
+ @state() private fullYearsHistogramAggregation: Aggregation | undefined;
165
+
166
+ /**
167
+ * The search type of the previous search (i.e., the currently displayed
168
+ * search results), which may differ from the one that is currently selected
169
+ * to be used for the next search.
170
+ */
171
+ @state() private previousSearchType?: SearchType;
172
+
173
+ @state() private totalResults?: number;
174
+
175
+ @state() private mobileView = false;
176
+
177
+ @state() private mobileFacetsVisible = false;
178
+
179
+ @state() private placeholderType: PlaceholderType = null;
180
+
181
+ @query('#content-container') private contentContainer!: HTMLDivElement;
182
+
183
+ private languageCodeHandler = new LanguageCodeHandler();
184
+
185
+ @property({ type: Object, attribute: false })
186
+ private analyticsHandler?: AnalyticsManagerInterface;
187
+
188
+ /**
189
+ * When we're animated scrolling to the page, we don't want to fetch
190
+ * all of the pages as it scrolls so this lets us know if we're scrolling
191
+ */
192
+ private isScrollingToCell = false;
193
+
194
+ /**
195
+ * When we've reached the end of the data, stop trying to fetch more
196
+ */
197
+ private endOfDataReached = false;
198
+
199
+ /**
200
+ * When page width resizes from desktop to mobile, set true to
201
+ * disable expand/collapse transition when loading.
202
+ */
203
+ private isResizeToMobile = false;
204
+
205
+ private placeholderCellTemplate = html`<collection-browser-loading-tile></collection-browser-loading-tile>`;
206
+
207
+ private tileModelAtCellIndex(index: number): TileModel | undefined {
208
+ const pageNumber = Math.floor(index / this.pageSize) + 1;
209
+ const itemIndex = index % this.pageSize;
210
+ const model = this.dataSource[pageNumber]?.[itemIndex];
211
+ /**
212
+ * If we encounter a model we don't have yet and we're not in the middle of an
213
+ * automated scroll, fetch the page and just return undefined.
214
+ * The datasource will be updated once the page is loaded and the cell will be rendered.
215
+ *
216
+ * We disable it during the automated scroll since we may fetch pages for cells the
217
+ * user may never see.
218
+ */
219
+ if (!model && !this.isScrollingToCell) {
220
+ this.fetchPage(pageNumber);
221
+ }
222
+ return model;
223
+ }
224
+
225
+ private get sortFilterQueries(): string {
226
+ const queries = [this.titleQuery, this.creatorQuery];
227
+ return queries.filter(q => q).join(' AND ');
228
+ }
229
+
230
+ // this is the total number of tiles we expect if
231
+ // the data returned is a full page worth
232
+ // this is useful for putting in placeholders for the expected number of tiles
233
+ private get estimatedTileCount(): number {
234
+ return this.pagesToRender * this.pageSize;
235
+ }
236
+
237
+ // this is the actual number of tiles in the datasource,
238
+ // which is useful for removing excess placeholder tiles
239
+ // once we reached the end of the data
240
+ private get actualTileCount(): number {
241
+ return Object.keys(this.dataSource).reduce(
242
+ (acc, page) => acc + this.dataSource[page].length,
243
+ 0
244
+ );
245
+ }
246
+
247
+ /**
248
+ * The results per page so we can paginate.
249
+ *
250
+ * This allows us to start in the middle of the search results and
251
+ * fetch data before or after the current page. If we don't have a key
252
+ * for the previous/next page, we'll fetch the next/previous page to populate it
253
+ */
254
+ private dataSource: Record<string, TileModel[]> = {};
255
+
256
+ @query('infinite-scroller')
257
+ private infiniteScroller!: InfiniteScroller;
258
+
259
+ /**
260
+ * Go to the given page of results
261
+ *
262
+ * @param pageNumber
263
+ */
264
+ goToPage(pageNumber: number) {
265
+ this.initialPageNumber = pageNumber;
266
+ this.pagesToRender = pageNumber;
267
+ this.scrollToPage(pageNumber);
268
+ }
269
+
270
+ clearFilters() {
271
+ this.selectedFacets = defaultSelectedFacets;
272
+ this.sortParam = null;
273
+ this.selectedTitleFilter = null;
274
+ this.selectedCreatorFilter = null;
275
+ this.titleQuery = undefined;
276
+ this.creatorQuery = undefined;
277
+ this.selectedSort = SortField.relevance;
278
+ this.sortDirection = null;
279
+ }
280
+
281
+ /**
282
+ * Manually requests to perform a search, which will only be executed if one of
283
+ * the query, the search type, or the sort has changed.
284
+ */
285
+ requestSearch() {
286
+ this.handleQueryChange();
287
+ }
288
+
289
+ render() {
290
+ this.setPlaceholderType();
291
+ return html`
292
+ <div
293
+ id="content-container"
294
+ class=${this.mobileView ? 'mobile' : 'desktop'}
295
+ >
296
+ ${this.placeholderType
297
+ ? this.emptyPlaceholderTemplate
298
+ : this.collectionBrowserTemplate}
299
+ </div>
300
+ `;
301
+ }
302
+
303
+ private setPlaceholderType() {
304
+ this.placeholderType = null;
305
+ if (!this.baseQuery) {
306
+ this.placeholderType = 'empty-query';
307
+ }
308
+
309
+ if (!this.searchResultsLoading && this.totalResults === 0) {
310
+ this.placeholderType = 'null-result';
311
+ }
312
+ }
313
+
314
+ private get emptyPlaceholderTemplate() {
315
+ return html`
316
+ <empty-placeholder
317
+ .placeholderType=${this.placeholderType}
318
+ ?isMobileView=${this.mobileView}
319
+ ></empty-placeholder>
320
+ `;
321
+ }
322
+
323
+ private get collectionBrowserTemplate() {
324
+ return html`<div
325
+ id="left-column"
326
+ class="column${this.isResizeToMobile ? ' preload' : ''}"
327
+ >
328
+ <div id="mobile-header-container">
329
+ ${this.mobileView ? this.mobileFacetsTemplate : nothing}
330
+ <div id="results-total">
331
+ <span id="big-results-count">
332
+ ${this.totalResults !== undefined
333
+ ? this.totalResults.toLocaleString()
334
+ : '-'}
335
+ </span>
336
+ <span id="big-results-label">
337
+ ${this.totalResults === 1 ? 'Result' : 'Results'}
338
+ </span>
339
+ </div>
340
+ </div>
341
+ <div
342
+ id="facets-container"
343
+ class=${!this.mobileView || this.mobileFacetsVisible
344
+ ? 'expanded'
345
+ : ''}
346
+ >
347
+ ${this.facetsTemplate}
348
+ </div>
349
+ </div>
350
+ <div id="right-column" class="column">
351
+ ${this.searchResultsLoading ? this.loadingTemplate : nothing}
352
+ ${this.sortFilterBarTemplate}
353
+ ${this.displayMode === `list-compact`
354
+ ? this.listHeaderTemplate
355
+ : nothing}
356
+ ${this.infiniteScrollerTemplate}
357
+ </div>`;
358
+ }
359
+
360
+ private get infiniteScrollerTemplate() {
361
+ return html`<infinite-scroller
362
+ class="${ifDefined(this.displayMode)}"
363
+ .cellProvider=${this}
364
+ .placeholderCellTemplate=${this.placeholderCellTemplate}
365
+ @scrollThresholdReached=${this.scrollThresholdReached}
366
+ @visibleCellsChanged=${this.visibleCellsChanged}
367
+ ></infinite-scroller>`;
368
+ }
369
+
370
+ private get sortFilterBarTemplate() {
371
+ return html`
372
+ <sort-filter-bar
373
+ .selectedSort=${this.selectedSort}
374
+ .sortDirection=${this.sortDirection}
375
+ .displayMode=${this.displayMode}
376
+ .selectedTitleFilter=${this.selectedTitleFilter}
377
+ .selectedCreatorFilter=${this.selectedCreatorFilter}
378
+ .resizeObserver=${this.resizeObserver}
379
+ @sortChanged=${this.userChangedSort}
380
+ @displayModeChanged=${this.displayModeChanged}
381
+ @titleLetterChanged=${this.titleLetterSelected}
382
+ @creatorLetterChanged=${this.creatorLetterSelected}
383
+ >
384
+ </sort-filter-bar>
385
+ `;
386
+ }
387
+
388
+ private userChangedSort(
389
+ e: CustomEvent<{
390
+ selectedSort: SortField;
391
+ sortDirection: SortDirection | null;
392
+ }>
393
+ ) {
394
+ const { selectedSort, sortDirection } = e.detail;
395
+ this.selectedSort = selectedSort;
396
+ this.sortDirection = sortDirection;
397
+
398
+ if ((this.currentPage ?? 1) > 1) {
399
+ this.goToPage(1);
400
+ }
401
+ this.currentPage = 1;
402
+ }
403
+
404
+ private sendSortByAnalytics(prevSortDirection: SortDirection | null): void {
405
+ const directionCleared = prevSortDirection && !this.sortDirection;
406
+
407
+ this.analyticsHandler?.sendEventNoSampling({
408
+ category: this.searchContext,
409
+ action: analyticsActions.sortBy,
410
+ label: `${this.selectedSort}${
411
+ this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''
412
+ }`,
413
+ });
414
+ }
415
+
416
+ private selectedSortChanged(): void {
417
+ if (this.selectedSort === 'relevance' || this.sortDirection === null) {
418
+ this.sortParam = null;
419
+ return;
420
+ }
421
+ const sortField = SortFieldToMetadataField[this.selectedSort];
422
+
423
+ if (!sortField) return;
424
+ this.sortParam = { field: sortField, direction: this.sortDirection };
425
+ }
426
+
427
+ private displayModeChanged(
428
+ e: CustomEvent<{ displayMode: CollectionDisplayMode }>
429
+ ) {
430
+ this.displayMode = e.detail.displayMode;
431
+
432
+ if (this.displayMode) {
433
+ this.analyticsHandler?.sendEventNoSampling({
434
+ category: this.searchContext,
435
+ action: analyticsActions.displayMode,
436
+ label: this.displayMode,
437
+ });
438
+ }
439
+ }
440
+
441
+ /** Send Analytics when sorting by title's first letter
442
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
443
+ * */
444
+ private sendFilterByTitleAnalytics(prevSelectedLetter: string | null): void {
445
+ if (!prevSelectedLetter && !this.selectedTitleFilter) {
446
+ return;
447
+ }
448
+ const cleared = prevSelectedLetter && this.selectedTitleFilter === null;
449
+
450
+ this.analyticsHandler?.sendEventNoSampling({
451
+ category: this.searchContext,
452
+ action: analyticsActions.filterByTitle,
453
+ label: cleared
454
+ ? `clear-${prevSelectedLetter}`
455
+ : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
456
+ });
457
+ }
458
+
459
+ private selectedTitleLetterChanged(): void {
460
+ this.titleQuery = this.selectedTitleFilter
461
+ ? `firstTitle:${this.selectedTitleFilter}`
462
+ : undefined;
463
+ }
464
+
465
+ /** Send Analytics when filtering by creator's first letter
466
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
467
+ * */
468
+ private sendFilterByCreatorAnalytics(
469
+ prevSelectedLetter: string | null
470
+ ): void {
471
+ if (!prevSelectedLetter && !this.selectedCreatorFilter) {
472
+ return;
473
+ }
474
+ const cleared = prevSelectedLetter && this.selectedCreatorFilter === null;
475
+
476
+ this.analyticsHandler?.sendEventNoSampling({
477
+ category: this.searchContext,
478
+ action: analyticsActions.filterByCreator,
479
+ label: cleared
480
+ ? `clear-${prevSelectedLetter}`
481
+ : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
482
+ });
483
+ }
484
+
485
+ private selectedCreatorLetterChanged(): void {
486
+ this.creatorQuery = this.selectedCreatorFilter
487
+ ? `firstCreator:${this.selectedCreatorFilter}`
488
+ : undefined;
489
+ }
490
+
491
+ private titleLetterSelected(e: CustomEvent<{ selectedLetter: string }>) {
492
+ this.selectedCreatorFilter = null;
493
+ this.selectedTitleFilter = e.detail.selectedLetter;
494
+ }
495
+
496
+ private creatorLetterSelected(e: CustomEvent<{ selectedLetter: string }>) {
497
+ this.selectedTitleFilter = null;
498
+ this.selectedCreatorFilter = e.detail.selectedLetter;
499
+ }
500
+
501
+ private get facetDataLoading(): boolean {
502
+ return (
503
+ this.facetsLoading ||
504
+ this.lendingFacetLoading ||
505
+ this.fullYearAggregationLoading
506
+ );
507
+ }
508
+
509
+ private get mobileFacetsTemplate() {
510
+ return html`
511
+ <div id="mobile-filter-collapse">
512
+ <h1
513
+ @click=${() => {
514
+ this.isResizeToMobile = false;
515
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
516
+ }}
517
+ @keyup=${() => {
518
+ this.isResizeToMobile = false;
519
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
520
+ }}
521
+ >
522
+ <span class="collapser ${this.mobileFacetsVisible ? 'open' : ''}">
523
+ ${chevronIcon}
524
+ </span>
525
+ Filters
526
+ </h1>
527
+ </div>
528
+ `;
529
+ }
530
+
531
+ private get facetsTemplate() {
532
+ return html`
533
+ ${this.facetsLoading ? this.loadingTemplate : nothing}
534
+ <collection-facets
535
+ @facetsChanged=${this.facetsChanged}
536
+ @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
537
+ .searchService=${this.searchService}
538
+ .searchType=${this.searchType}
539
+ .aggregations=${this.aggregations}
540
+ .fullYearsHistogramAggregation=${this.fullYearsHistogramAggregation}
541
+ .moreLinksVisible=${this.previousSearchType !== SearchType.FULLTEXT}
542
+ .minSelectedDate=${this.minSelectedDate}
543
+ .maxSelectedDate=${this.maxSelectedDate}
544
+ .selectedFacets=${this.selectedFacets}
545
+ .collectionNameCache=${this.collectionNameCache}
546
+ .languageCodeHandler=${this.languageCodeHandler}
547
+ .showHistogramDatePicker=${this.showHistogramDatePicker}
548
+ .fullQuery=${this.fullQuery}
549
+ .modalManager=${this.modalManager}
550
+ ?collapsableFacets=${this.mobileView}
551
+ ?facetsLoading=${this.facetDataLoading}
552
+ ?fullYearAggregationLoading=${this.fullYearAggregationLoading}
553
+ .onFacetClick=${this.facetClickHandler}
554
+ .analyticsHandler=${this.analyticsHandler}
555
+ >
556
+ </collection-facets>
557
+ `;
558
+ }
559
+
560
+ private get loadingTemplate() {
561
+ return html`
562
+ <div class="loading-cover">
563
+ <circular-activity-indicator></circular-activity-indicator>
564
+ </div>
565
+ `;
566
+ }
567
+
568
+ private get listHeaderTemplate() {
569
+ return html`
570
+ <div id="list-header">
571
+ <tile-dispatcher
572
+ .tileDisplayMode=${'list-header'}
573
+ .resizeObserver=${this.resizeObserver}
574
+ .sortParam=${this.sortParam}
575
+ .mobileBreakpoint=${this.mobileBreakpoint}
576
+ .loggedIn=${this.loggedIn}
577
+ >
578
+ </tile-dispatcher>
579
+ </div>
580
+ `;
581
+ }
582
+
583
+ private get queryDebuggingTemplate() {
584
+ return html`
585
+ <div>
586
+ <ul>
587
+ <li>Base Query: ${this.baseQuery}</li>
588
+ <li>Facet Query: ${this.facetQuery}</li>
589
+ <li>Sort Filter Query: ${this.sortFilterQueries}</li>
590
+ <li>Date Range Query: ${this.dateRangeQueryClause}</li>
591
+ <li>Sort: ${this.sortParam?.field} ${this.sortParam?.direction}</li>
592
+ <li>Full Query: ${this.fullQuery}</li>
593
+ </ul>
594
+ </div>
595
+ `;
596
+ }
597
+
598
+ private histogramDateRangeUpdated(
599
+ e: CustomEvent<{
600
+ minDate: string;
601
+ maxDate: string;
602
+ }>
603
+ ) {
604
+ const { minDate, maxDate } = e.detail;
605
+ this.dateRangeQueryClause = `year:[${minDate} TO ${maxDate}]`;
606
+
607
+ if (this.dateRangeQueryClause) {
608
+ this.analyticsHandler?.sendEventNoSampling({
609
+ category: this.searchContext,
610
+ action: analyticsActions.histogramChanged,
611
+ label: this.dateRangeQueryClause,
612
+ });
613
+ }
614
+ }
615
+
616
+ firstUpdated(): void {
617
+ this.setupStateRestorationObserver();
618
+ this.restoreState();
619
+ }
620
+
621
+ updated(changed: PropertyValues) {
622
+ if (
623
+ changed.has('displayMode') ||
624
+ changed.has('baseNavigationUrl') ||
625
+ changed.has('baseImageUrl') ||
626
+ changed.has('loggedIn')
627
+ ) {
628
+ this.infiniteScroller?.reload();
629
+ }
630
+ if (changed.has('baseQuery')) {
631
+ this.emitBaseQueryChanged();
632
+ }
633
+ if (changed.has('currentPage') || changed.has('displayMode')) {
634
+ this.persistState();
635
+ }
636
+ if (
637
+ changed.has('baseQuery') ||
638
+ changed.has('titleQuery') ||
639
+ changed.has('creatorQuery') ||
640
+ changed.has('dateRangeQueryClause') ||
641
+ changed.has('sortParam') ||
642
+ changed.has('selectedFacets') ||
643
+ changed.has('searchService')
644
+ ) {
645
+ this.handleQueryChange();
646
+ }
647
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
648
+ const prevSortDirection = changed.get('sortDirection') as SortDirection;
649
+ this.sendSortByAnalytics(prevSortDirection);
650
+ this.selectedSortChanged();
651
+ }
652
+ if (changed.has('selectedTitleFilter')) {
653
+ this.sendFilterByTitleAnalytics(
654
+ changed.get('selectedTitleFilter') as string
655
+ );
656
+ this.selectedTitleLetterChanged();
657
+ }
658
+ if (changed.has('selectedCreatorFilter')) {
659
+ this.sendFilterByCreatorAnalytics(
660
+ changed.get('selectedCreatorFilter') as string
661
+ );
662
+ this.selectedCreatorLetterChanged();
663
+ }
664
+ if (changed.has('pagesToRender')) {
665
+ if (!this.endOfDataReached && this.infiniteScroller) {
666
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
667
+ }
668
+ }
669
+ if (changed.has('resizeObserver')) {
670
+ const oldObserver = changed.get(
671
+ 'resizeObserver'
672
+ ) as SharedResizeObserverInterface;
673
+ if (oldObserver) this.disconnectResizeObserver(oldObserver);
674
+ this.setupResizeObserver();
675
+ }
676
+ }
677
+
678
+ disconnectedCallback(): void {
679
+ if (this.resizeObserver) {
680
+ this.disconnectResizeObserver(this.resizeObserver);
681
+ }
682
+ if (this.boundNavigationHandler) {
683
+ window.removeEventListener('popstate', this.boundNavigationHandler);
684
+ }
685
+ }
686
+
687
+ handleResize(entry: ResizeObserverEntry): void {
688
+ const previousView = this.mobileView;
689
+ if (entry.target === this.contentContainer) {
690
+ this.mobileView = entry.contentRect.width < this.mobileBreakpoint;
691
+ // If changing from desktop to mobile disable transition
692
+ if (this.mobileView && !previousView) {
693
+ this.isResizeToMobile = true;
694
+ }
695
+ }
696
+ }
697
+
698
+ private emitBaseQueryChanged() {
699
+ this.dispatchEvent(
700
+ new CustomEvent<{ baseQuery?: string }>('baseQueryChanged', {
701
+ detail: {
702
+ baseQuery: this.baseQuery,
703
+ },
704
+ })
705
+ );
706
+ }
707
+
708
+ private disconnectResizeObserver(
709
+ resizeObserver: SharedResizeObserverInterface
710
+ ) {
711
+ resizeObserver.removeObserver({
712
+ target: this.contentContainer,
713
+ handler: this,
714
+ });
715
+ }
716
+
717
+ private setupResizeObserver() {
718
+ if (!this.resizeObserver) return;
719
+ this.resizeObserver.addObserver({
720
+ target: this.contentContainer,
721
+ handler: this,
722
+ });
723
+ }
724
+
725
+ /**
726
+ * When the visible cells change from the infinite scroller, we want to emit
727
+ * which page is currently visible so the consumer can update its UI or the URL
728
+ *
729
+ * @param e
730
+ * @returns
731
+ */
732
+ private visibleCellsChanged(
733
+ e: CustomEvent<{ visibleCellIndices: number[] }>
734
+ ) {
735
+ if (this.isScrollingToCell) return;
736
+ const { visibleCellIndices } = e.detail;
737
+ if (visibleCellIndices.length === 0) return;
738
+ const lastVisibleCellIndex =
739
+ visibleCellIndices[visibleCellIndices.length - 1];
740
+ const lastVisibleCellPage =
741
+ Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
742
+ if (this.currentPage !== lastVisibleCellPage) {
743
+ this.currentPage = lastVisibleCellPage;
744
+ }
745
+ const event = new CustomEvent('visiblePageChanged', {
746
+ detail: {
747
+ pageNumber: lastVisibleCellPage,
748
+ },
749
+ });
750
+ this.dispatchEvent(event);
751
+ }
752
+
753
+ // we only want to scroll on the very first query change
754
+ // so this keeps track of whether we've already set the initial query
755
+ private initialQueryChangeHappened = false;
756
+
757
+ private historyPopOccurred = false;
758
+
759
+ // this lets us store the query key so we know if it's actually changed or not
760
+ private previousQueryKey?: string;
761
+
762
+ private async handleQueryChange() {
763
+ // only reset if the query has actually changed
764
+ if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
765
+ return;
766
+ this.previousQueryKey = this.pageFetchQueryKey;
767
+
768
+ this.dataSource = {};
769
+ this.pageFetchesInProgress = {};
770
+ this.endOfDataReached = false;
771
+ this.pagesToRender = this.initialPageNumber;
772
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
773
+ this.scrollToPage(this.initialPageNumber);
774
+ }
775
+ this.initialQueryChangeHappened = true;
776
+ // if the query changed as part of a window.history pop event, we don't want to
777
+ // persist the state because it overwrites the forward history
778
+ if (!this.historyPopOccurred) {
779
+ this.persistState();
780
+ this.historyPopOccurred = false;
781
+ }
782
+
783
+ // Ensure lending aggregations don't carry over to non-metadata searches
784
+ if (this.searchType !== SearchType.METADATA) {
785
+ delete this.aggregations?.lending;
786
+ }
787
+
788
+ await Promise.all([
789
+ this.doInitialPageFetch(),
790
+ this.fetchFacets(),
791
+ this.fetchLendingFacet(),
792
+ this.fetchFullYearHistogram(),
793
+ ]);
794
+ }
795
+
796
+ private setupStateRestorationObserver() {
797
+ if (this.boundNavigationHandler) return;
798
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
799
+ // when the user navigates back, we want to update the UI to match the URL
800
+ window.addEventListener('popstate', this.boundNavigationHandler);
801
+ }
802
+
803
+ private boundNavigationHandler?: () => void;
804
+
805
+ private historyNavigationHandler() {
806
+ this.historyPopOccurred = true;
807
+ this.restoreState();
808
+ }
809
+
810
+ private restoreState() {
811
+ const restorationState = this.restorationStateHandler.getRestorationState();
812
+ this.displayMode = restorationState.displayMode;
813
+ this.selectedSort = restorationState.selectedSort ?? SortField.relevance;
814
+ this.sortDirection = restorationState.sortDirection ?? null;
815
+ this.selectedTitleFilter = restorationState.selectedTitleFilter ?? null;
816
+ this.selectedCreatorFilter = restorationState.selectedCreatorFilter ?? null;
817
+ this.selectedFacets = restorationState.selectedFacets;
818
+ this.baseQuery = restorationState.baseQuery;
819
+ this.titleQuery = restorationState.titleQuery;
820
+ this.creatorQuery = restorationState.creatorQuery;
821
+ this.dateRangeQueryClause = restorationState.dateRangeQueryClause;
822
+ this.sortParam = restorationState.sortParam ?? null;
823
+ this.currentPage = restorationState.currentPage ?? 1;
824
+ this.minSelectedDate = restorationState.minSelectedDate;
825
+ this.maxSelectedDate = restorationState.maxSelectedDate;
826
+ if (this.currentPage > 1) {
827
+ this.goToPage(this.currentPage);
828
+ }
829
+ }
830
+
831
+ private persistState() {
832
+ const restorationState: RestorationState = {
833
+ displayMode: this.displayMode,
834
+ sortParam: this.sortParam ?? undefined,
835
+ selectedSort: this.selectedSort,
836
+ sortDirection: this.sortDirection ?? undefined,
837
+ selectedFacets: this.selectedFacets ?? defaultSelectedFacets,
838
+ baseQuery: this.baseQuery,
839
+ currentPage: this.currentPage,
840
+ dateRangeQueryClause: this.dateRangeQueryClause,
841
+ titleQuery: this.titleQuery,
842
+ creatorQuery: this.creatorQuery,
843
+ minSelectedDate: this.minSelectedDate,
844
+ maxSelectedDate: this.maxSelectedDate,
845
+ selectedTitleFilter: this.selectedTitleFilter ?? undefined,
846
+ selectedCreatorFilter: this.selectedCreatorFilter ?? undefined,
847
+ };
848
+ this.restorationStateHandler.persistState(restorationState);
849
+ }
850
+
851
+ private async doInitialPageFetch() {
852
+ this.searchResultsLoading = true;
853
+ await this.fetchPage(this.initialPageNumber);
854
+ this.searchResultsLoading = false;
855
+ }
856
+
857
+ private get fullQuery(): string | undefined {
858
+ let { fullQueryWithoutDate } = this;
859
+ const { dateRangeQueryClause } = this;
860
+ if (dateRangeQueryClause) {
861
+ fullQueryWithoutDate += ` AND ${dateRangeQueryClause}`;
862
+ }
863
+ return fullQueryWithoutDate;
864
+ }
865
+
866
+ private get fullQueryWithoutDate(): string | undefined {
867
+ if (!this.baseQuery) return undefined;
868
+ let fullQuery = this.baseQuery;
869
+ const { facetQuery, sortFilterQueries } = this;
870
+ if (facetQuery) {
871
+ fullQuery += ` AND ${facetQuery}`;
872
+ }
873
+ if (sortFilterQueries) {
874
+ fullQuery += ` AND ${sortFilterQueries}`;
875
+ }
876
+ return fullQuery;
877
+ }
878
+
879
+ /**
880
+ * Generates a query string for the given facets
881
+ *
882
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
883
+ */
884
+ private get facetQuery(): string | undefined {
885
+ if (!this.selectedFacets) return undefined;
886
+ const facetQuery = [];
887
+ for (const [facetName, facetValues] of Object.entries(
888
+ this.selectedFacets
889
+ )) {
890
+ const facetEntries = Object.entries(facetValues);
891
+ const facetQueryName =
892
+ facetName === 'lending' ? 'lending___status' : facetName;
893
+ // eslint-disable-next-line no-continue
894
+ if (facetEntries.length === 0) continue;
895
+ const facetValuesArray: string[] = [];
896
+ for (const [key, facetData] of facetEntries) {
897
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
898
+
899
+ if (facetName === 'language') {
900
+ const languages =
901
+ this.languageCodeHandler.getCodeArrayFromCodeString(key);
902
+ for (const language of languages) {
903
+ facetValuesArray.push(`${plusMinusPrefix}"${language}"`);
904
+ }
905
+ } else {
906
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
907
+ }
908
+ }
909
+ const valueQuery = facetValuesArray.join(` OR `);
910
+ facetQuery.push(`${facetQueryName}:(${valueQuery})`);
911
+ }
912
+ return facetQuery.length > 0 ? `(${facetQuery.join(' AND ')})` : undefined;
913
+ }
914
+
915
+ facetsChanged(e: CustomEvent<SelectedFacets>) {
916
+ this.selectedFacets = e.detail;
917
+ }
918
+
919
+ facetClickHandler(
920
+ name: FacetOption,
921
+ facetSelected: boolean,
922
+ negative: boolean
923
+ ): void {
924
+ if (negative) {
925
+ this.analyticsHandler?.sendEventNoSampling({
926
+ category: this.searchContext,
927
+ action: facetSelected
928
+ ? analyticsActions.facetNegativeSelected
929
+ : analyticsActions.facetNegativeDeselected,
930
+ label: name,
931
+ });
932
+ } else {
933
+ this.analyticsHandler?.sendEventNoSampling({
934
+ category: this.searchContext,
935
+ action: facetSelected
936
+ ? analyticsActions.facetSelected
937
+ : analyticsActions.facetDeselected,
938
+ label: name,
939
+ });
940
+ }
941
+ }
942
+
943
+ private async fetchFacets() {
944
+ if (!this.fullQuery) return;
945
+
946
+ const params: SearchParams = {
947
+ query: this.fullQuery,
948
+ rows: 0,
949
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
950
+ // The default aggregations for the search_results page type should be what we need here.
951
+ };
952
+
953
+ this.facetsLoading = true;
954
+ this.previousSearchType = this.searchType;
955
+ const results = await this.searchService?.search(params, this.searchType);
956
+ this.facetsLoading = false;
957
+
958
+ this.aggregations = {
959
+ ...this.aggregations,
960
+ ...results?.success?.response.aggregations,
961
+ };
962
+ }
963
+
964
+ private async fetchLendingFacet() {
965
+ // Only retrieve lending facet for metadata searches
966
+ if (this.searchType !== SearchType.METADATA) return;
967
+ if (!this.fullQuery) return;
968
+
969
+ const params: SearchParams = {
970
+ query: this.fullQuery,
971
+ rows: 0,
972
+ aggregations: {
973
+ simpleParams: ['lending___status'],
974
+ },
975
+ aggregationsSize: 10, // Larger size to ensure we get all possible statuses
976
+ };
977
+
978
+ this.lendingFacetLoading = true;
979
+ const results = await this.searchService?.search(params, this.searchType);
980
+ this.lendingFacetLoading = false;
981
+
982
+ this.aggregations = {
983
+ ...this.aggregations,
984
+ ...results?.success?.response.aggregations,
985
+ };
986
+ }
987
+
988
+ /**
989
+ * If we haven't changed the query, we don't need to fetch the full year histogram
990
+ *
991
+ * @private
992
+ * @type {string}
993
+ * @memberof CollectionBrowser
994
+ */
995
+ private previousFullQueryNoDate?: string;
996
+
997
+ /**
998
+ * The query key is a string that uniquely identifies the current query
999
+ * without the date range.
1000
+ *
1001
+ * If this doesn't change, we don't need to re-fetch the histogram date range
1002
+ */
1003
+ private get fullQueryNoDateKey() {
1004
+ return `${this.fullQueryWithoutDate}-${this.searchType}-${this.sortParam?.field}-${this.sortParam?.direction}`;
1005
+ }
1006
+
1007
+ /**
1008
+ * This method is similar to fetching the facets above,
1009
+ * but only fetching the year histogram. There is a subtle difference
1010
+ * in how you have to fetch the year histogram where you can't use the
1011
+ * advanced JSON syntax like the other aggregations. It's a special
1012
+ * case that @ximm put it place.
1013
+ */
1014
+ private async fetchFullYearHistogram(): Promise<void> {
1015
+ const { fullQueryNoDateKey } = this;
1016
+ if (
1017
+ !this.fullQueryWithoutDate ||
1018
+ fullQueryNoDateKey === this.previousFullQueryNoDate
1019
+ )
1020
+ return;
1021
+ this.previousFullQueryNoDate = fullQueryNoDateKey;
1022
+
1023
+ const aggregations = {
1024
+ simpleParams: ['year'],
1025
+ };
1026
+
1027
+ const params = {
1028
+ query: this.fullQueryWithoutDate,
1029
+ aggregations,
1030
+ rows: 0,
1031
+ };
1032
+
1033
+ this.fullYearAggregationLoading = true;
1034
+ const results = await this.searchService?.search(params, this.searchType);
1035
+ this.fullYearAggregationLoading = false;
1036
+
1037
+ this.fullYearsHistogramAggregation =
1038
+ results?.success?.response?.aggregations?.year_histogram;
1039
+ }
1040
+
1041
+ private scrollToPage(pageNumber: number) {
1042
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1043
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1044
+ // then scrolls to the cell
1045
+ setTimeout(() => {
1046
+ this.isScrollingToCell = true;
1047
+ this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
1048
+ // This timeout is to give the scroll animation time to finish
1049
+ // then updating the infinite scroller once we're done scrolling
1050
+ // There's no scroll animation completion callback so we're
1051
+ // giving it 0.5s to finish.
1052
+ setTimeout(() => {
1053
+ this.isScrollingToCell = false;
1054
+ this.infiniteScroller.reload();
1055
+ }, 500);
1056
+ }, 0);
1057
+ }
1058
+
1059
+ /**
1060
+ * The query key is a string that uniquely identifies the current query
1061
+ *
1062
+ * This lets us keep track of queries so we don't persist data that's
1063
+ * no longer relevant.
1064
+ */
1065
+ private get pageFetchQueryKey() {
1066
+ return `${this.fullQuery}-${this.searchType}-${this.sortParam?.field}-${this.sortParam?.direction}`;
1067
+ }
1068
+
1069
+ // this maps the query to the pages being fetched for that query
1070
+ private pageFetchesInProgress: Record<string, Set<number>> = {};
1071
+
1072
+ async fetchPage(pageNumber: number) {
1073
+ if (!this.fullQuery) return;
1074
+
1075
+ // if we already have data, don't fetch again
1076
+ if (this.dataSource[pageNumber]) return;
1077
+
1078
+ if (this.endOfDataReached) return;
1079
+
1080
+ // if a fetch is already in progress for this query and page, don't fetch again
1081
+ const { pageFetchQueryKey } = this;
1082
+ const pageFetches =
1083
+ this.pageFetchesInProgress[pageFetchQueryKey] ?? new Set();
1084
+ if (pageFetches.has(pageNumber)) return;
1085
+ pageFetches.add(pageNumber);
1086
+ this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1087
+
1088
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1089
+ const params: SearchParams = {
1090
+ query: this.fullQuery,
1091
+ fields: [
1092
+ 'addeddate',
1093
+ 'avg_rating',
1094
+ 'collections_raw',
1095
+ 'creator',
1096
+ 'date',
1097
+ 'description',
1098
+ 'downloads',
1099
+ 'identifier',
1100
+ 'issue',
1101
+ 'item_count',
1102
+ 'mediatype',
1103
+ 'num_favorites',
1104
+ 'num_reviews',
1105
+ 'publicdate',
1106
+ 'reviewdate',
1107
+ 'source',
1108
+ 'subject', // topic
1109
+ 'title',
1110
+ 'volume',
1111
+ ],
1112
+ page: pageNumber,
1113
+ rows: this.pageSize,
1114
+ sort: sortParams,
1115
+ aggregations: { omit: true },
1116
+ };
1117
+ const searchResponse = await this.searchService?.search(
1118
+ params,
1119
+ this.searchType
1120
+ );
1121
+ const success = searchResponse?.success;
1122
+
1123
+ if (!success) return;
1124
+
1125
+ this.totalResults = success.response.totalResults;
1126
+
1127
+ // this is checking to see if the query has changed since the data was fetched
1128
+ // if so, we just want to discard the data since there should be a new query
1129
+ // right behind it
1130
+ const searchQuery = success.request.clientParameters.user_query;
1131
+ const searchSort = success.request.clientParameters.sort;
1132
+ let sortChanged = false;
1133
+ if (!searchSort || searchSort.length === 0) {
1134
+ // if we went from no sort to sort, the sort has changed
1135
+ if (this.sortParam) {
1136
+ sortChanged = true;
1137
+ }
1138
+ } else {
1139
+ // check if the sort has changed
1140
+ for (const sortType of searchSort) {
1141
+ const [field, direction] = sortType.split(':');
1142
+ if (
1143
+ field !== this.sortParam?.field ||
1144
+ direction !== this.sortParam?.direction
1145
+ ) {
1146
+ sortChanged = true;
1147
+ break;
1148
+ }
1149
+ }
1150
+ }
1151
+ const queryChangedSinceFetch =
1152
+ searchQuery !== this.fullQuery || sortChanged;
1153
+ if (queryChangedSinceFetch) return;
1154
+
1155
+ const { results } = success.response;
1156
+ if (results && results.length > 0) {
1157
+ this.preloadCollectionNames(results);
1158
+ this.updateDataSource(pageNumber, results);
1159
+ }
1160
+ if (results.length < this.pageSize) {
1161
+ this.endOfDataReached = true;
1162
+ // this updates the infinite scroller to show the actual size
1163
+ if (this.infiniteScroller) {
1164
+ this.infiniteScroller.itemCount = this.actualTileCount;
1165
+ }
1166
+ }
1167
+ this.pageFetchesInProgress[pageFetchQueryKey]?.delete(pageNumber);
1168
+ this.searchResultsLoading = false;
1169
+ }
1170
+
1171
+ private preloadCollectionNames(results: SearchResult[]) {
1172
+ const collectionIds = results
1173
+ .map(result => result.collection?.values)
1174
+ .flat();
1175
+ const collectionIdsArray = Array.from(new Set(collectionIds)) as string[];
1176
+ this.collectionNameCache?.preloadIdentifiers(collectionIdsArray);
1177
+ }
1178
+
1179
+ /**
1180
+ * This is useful for determining whether we need to reload the scroller.
1181
+ *
1182
+ * When the fetch completes, we need to reload the scroller if the cells for that
1183
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
1184
+ */
1185
+ private get currentVisiblePageNumbers(): number[] {
1186
+ const visibleCells = this.infiniteScroller?.getVisibleCellIndices() ?? [];
1187
+ const visiblePages = new Set<number>();
1188
+ visibleCells.forEach(cellIndex => {
1189
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1190
+ visiblePages.add(visiblePage);
1191
+ });
1192
+ return Array.from(visiblePages);
1193
+ }
1194
+
1195
+ /**
1196
+ * Update the datasource from the fetch response
1197
+ *
1198
+ * @param pageNumber
1199
+ * @param results
1200
+ */
1201
+ private updateDataSource(pageNumber: number, results: SearchResult[]) {
1202
+ // copy our existing datasource so when we set it below, it gets set
1203
+ // instead of modifying the existing dataSource since object changes
1204
+ // don't trigger a re-render
1205
+ const datasource = { ...this.dataSource };
1206
+ const tiles: TileModel[] = [];
1207
+ results?.forEach(result => {
1208
+ if (!result.identifier) return;
1209
+
1210
+ let loginRequired = false;
1211
+ let contentWarning = false;
1212
+ // Check if item and item in "modifying" collection, setting above flags
1213
+ if (
1214
+ result.collection?.values.length &&
1215
+ result.mediatype?.value !== 'collection'
1216
+ ) {
1217
+ for (const collection of result.collection?.values ?? []) {
1218
+ if (collection === 'loggedin') {
1219
+ loginRequired = true;
1220
+ if (contentWarning) break;
1221
+ }
1222
+ if (collection === 'no-preview') {
1223
+ contentWarning = true;
1224
+ if (loginRequired) break;
1225
+ }
1226
+ }
1227
+ }
1228
+
1229
+ tiles.push({
1230
+ // TODO the commented items are not currently being returned by the PPS and
1231
+ // we will need to have them added to the PPS hit schemas where appropriate
1232
+
1233
+ // averageRating: result.avg_rating?.value,
1234
+ collections: result.collection?.values ?? [],
1235
+ commentCount: result.num_reviews?.value ?? 0,
1236
+ creator: result.creator?.value,
1237
+ creators: result.creator?.values ?? [],
1238
+ // dateAdded: result.addeddate?.value,
1239
+ dateArchived: result.publicdate?.value,
1240
+ datePublished: result.date?.value,
1241
+ dateReviewed: result.reviewdate?.value,
1242
+ description: result.description?.value,
1243
+ favCount: result.num_favorites?.value ?? 0,
1244
+ identifier: result.identifier,
1245
+ // issue: result.issue?.value,
1246
+ itemCount: 0, // result.item_count?.value ?? 0,
1247
+ mediatype: result.mediatype?.value ?? 'data',
1248
+ snippets: result.highlight?.values ?? [],
1249
+ // source: result.source?.value,
1250
+ subjects: result.subject?.values ?? [],
1251
+ title: this.etreeTitle(
1252
+ result.title?.value,
1253
+ result.mediatype?.value,
1254
+ result.collection?.values
1255
+ ),
1256
+ volume: result.volume?.value,
1257
+ viewCount: result.downloads?.value ?? 0,
1258
+ loginRequired,
1259
+ contentWarning,
1260
+ });
1261
+ });
1262
+ datasource[pageNumber] = tiles;
1263
+ this.dataSource = datasource;
1264
+ const visiblePages = this.currentVisiblePageNumbers;
1265
+ const needsReload = visiblePages.includes(pageNumber);
1266
+ if (needsReload) {
1267
+ this.infiniteScroller.reload();
1268
+ }
1269
+ }
1270
+
1271
+ /*
1272
+ * Convert etree titles
1273
+ * "[Creator] Live at [Place] on [Date]" => "[Date]: [Place]"
1274
+ *
1275
+ * Todo: Check collection(s) for etree, need to get as array.
1276
+ * Current search-service only returns first collection as string.
1277
+ */
1278
+ private etreeTitle(
1279
+ title: string | undefined,
1280
+ mediatype: string | undefined,
1281
+ collections: string[] | undefined
1282
+ ): string {
1283
+ if (mediatype === 'etree' || collections?.includes('etree')) {
1284
+ const regex = /^(.*) Live at (.*) on (\d\d\d\d-\d\d-\d\d)$/;
1285
+ const newTitle = title?.replace(regex, '$3: $2');
1286
+ if (newTitle) {
1287
+ return `${newTitle}`;
1288
+ }
1289
+ }
1290
+ return title ?? '';
1291
+ }
1292
+
1293
+ /**
1294
+ * Callback when a result is selected
1295
+ */
1296
+ resultSelected(event: CustomEvent<TileModel>): void {
1297
+ this.analyticsHandler?.sendEventNoSampling({
1298
+ category: this.searchContext,
1299
+ action: analyticsActions.resultSelected,
1300
+ label: event.detail.mediatype,
1301
+ });
1302
+
1303
+ this.analyticsHandler?.sendEventNoSampling({
1304
+ category: this.searchContext,
1305
+ action: analyticsActions.resultSelected,
1306
+ label: `page-${this.currentPage}`,
1307
+ });
1308
+ }
1309
+
1310
+ cellForIndex(index: number): TemplateResult | undefined {
1311
+ const model = this.tileModelAtCellIndex(index);
1312
+ if (!model) return undefined;
1313
+
1314
+ return html`
1315
+ <tile-dispatcher
1316
+ .baseNavigationUrl=${this.baseNavigationUrl}
1317
+ .baseImageUrl=${this.baseImageUrl}
1318
+ .model=${model}
1319
+ .tileDisplayMode=${this.displayMode}
1320
+ .resizeObserver=${this.resizeObserver}
1321
+ .collectionNameCache=${this.collectionNameCache}
1322
+ .sortParam=${this.sortParam}
1323
+ .mobileBreakpoint=${this.mobileBreakpoint}
1324
+ .loggedIn=${this.loggedIn}
1325
+ @resultSelected=${(e: CustomEvent) => this.resultSelected(e)}
1326
+ >
1327
+ </tile-dispatcher>
1328
+ `;
1329
+ }
1330
+
1331
+ /**
1332
+ * When the user scrolls near to the bottom of the page, fetch the next page
1333
+ * increase the number of pages to render and start fetching data for the new page
1334
+ */
1335
+ private scrollThresholdReached() {
1336
+ this.pagesToRender += 1;
1337
+ this.fetchPage(this.pagesToRender);
1338
+ }
1339
+
1340
+ static styles = css`
1341
+ :host {
1342
+ display: block;
1343
+ }
1344
+
1345
+ /**
1346
+ * When page width resizes from desktop to mobile, use this class to
1347
+ * disable expand/collapse transition when loading.
1348
+ */
1349
+ .preload * {
1350
+ transition: none !important;
1351
+ -webkit-transition: none !important;
1352
+ -moz-transition: none !important;
1353
+ -ms-transition: none !important;
1354
+ -o-transition: none !important;
1355
+ }
1356
+
1357
+ #content-container {
1358
+ display: flex;
1359
+ }
1360
+
1361
+ .collapser {
1362
+ display: inline-block;
1363
+ }
1364
+
1365
+ .collapser svg {
1366
+ width: 10px;
1367
+ height: 10px;
1368
+ transition: transform 0.2s ease-out;
1369
+ }
1370
+
1371
+ .collapser.open svg {
1372
+ transform: rotate(90deg);
1373
+ }
1374
+
1375
+ #mobile-filter-collapse h1 {
1376
+ cursor: pointer;
1377
+ }
1378
+
1379
+ #content-container.mobile {
1380
+ display: block;
1381
+ }
1382
+
1383
+ .column {
1384
+ padding-top: 2rem;
1385
+ }
1386
+
1387
+ #right-column {
1388
+ flex: 1;
1389
+ position: relative;
1390
+ border-left: 1px solid rgb(232, 232, 232);
1391
+ padding-left: 1rem;
1392
+ }
1393
+
1394
+ .mobile #right-column {
1395
+ border-left: none;
1396
+ padding: 0;
1397
+ }
1398
+
1399
+ #left-column {
1400
+ width: 18rem;
1401
+ min-width: 18rem; /* Prevents Safari from shrinking col at first draw */
1402
+ padding-right: 12px;
1403
+ padding-right: 1rem;
1404
+ }
1405
+
1406
+ .desktop #left-column::-webkit-scrollbar {
1407
+ display: none;
1408
+ }
1409
+
1410
+ .mobile #left-column {
1411
+ width: 100%;
1412
+ padding: 0;
1413
+ }
1414
+
1415
+ .desktop #left-column {
1416
+ top: 0;
1417
+ position: sticky;
1418
+ max-height: 100vh;
1419
+ overflow: scroll;
1420
+ -ms-overflow-style: none; /* hide scrollbar IE and Edge */
1421
+ scrollbar-width: none; /* hide scrollbar Firefox */
1422
+ }
1423
+
1424
+ #mobile-header-container {
1425
+ display: flex;
1426
+ justify-content: space-between;
1427
+ }
1428
+
1429
+ #facets-container {
1430
+ position: relative;
1431
+ max-height: 0;
1432
+ transition: max-height 0.2s ease-in-out;
1433
+ z-index: 1;
1434
+ padding-bottom: 2rem;
1435
+ }
1436
+
1437
+ .mobile #facets-container {
1438
+ overflow: hidden;
1439
+ padding-bottom: 0;
1440
+ }
1441
+
1442
+ #facets-container.expanded {
1443
+ max-height: 2000px;
1444
+ }
1445
+
1446
+ #results-total {
1447
+ display: flex;
1448
+ align-items: center;
1449
+ margin-bottom: 5rem;
1450
+ }
1451
+
1452
+ .mobile #results-total {
1453
+ margin-bottom: 0;
1454
+ }
1455
+
1456
+ #big-results-count {
1457
+ font-size: 2.4rem;
1458
+ font-weight: 500;
1459
+ margin-right: 5px;
1460
+ }
1461
+
1462
+ #big-results-label {
1463
+ font-size: 1rem;
1464
+ font-weight: 200;
1465
+ text-transform: uppercase;
1466
+ }
1467
+
1468
+ #list-header {
1469
+ max-height: 4.2rem;
1470
+ }
1471
+
1472
+ .loading-cover {
1473
+ position: absolute;
1474
+ top: 0;
1475
+ left: 0;
1476
+ width: 100%;
1477
+ height: 100%;
1478
+ display: flex;
1479
+ justify-content: center;
1480
+ z-index: 1;
1481
+ padding-top: 50px;
1482
+ }
1483
+
1484
+ circular-activity-indicator {
1485
+ width: 30px;
1486
+ height: 30px;
1487
+ }
1488
+
1489
+ sort-filter-bar {
1490
+ display: block;
1491
+ margin-bottom: 4rem;
1492
+ }
1493
+
1494
+ infinite-scroller {
1495
+ display: block;
1496
+ --infiniteScrollerRowGap: var(--collectionBrowserRowGap, 1.7rem);
1497
+ --infiniteScrollerColGap: var(--collectionBrowserColGap, 1.7rem);
1498
+ }
1499
+
1500
+ infinite-scroller.list-compact {
1501
+ --infiniteScrollerCellMinWidth: var(
1502
+ --collectionBrowserCellMinWidth,
1503
+ 100%
1504
+ );
1505
+ --infiniteScrollerCellMinHeight: 34px; /* override infinite scroller component */
1506
+ --infiniteScrollerCellMaxHeight: 56px;
1507
+ --infiniteScrollerRowGap: 0px;
1508
+ }
1509
+
1510
+ infinite-scroller.list-detail {
1511
+ --infiniteScrollerCellMinWidth: var(
1512
+ --collectionBrowserCellMinWidth,
1513
+ 100%
1514
+ );
1515
+ --infiniteScrollerCellMinHeight: var(
1516
+ --collectionBrowserCellMinHeight,
1517
+ 5rem
1518
+ );
1519
+ /*
1520
+ 30px in spec, compensating for a -4px margin
1521
+ to align title with top of item image
1522
+ src/tiles/list/tile-list.ts
1523
+ */
1524
+ --infiniteScrollerRowGap: 34px;
1525
+ }
1526
+
1527
+ .mobile infinite-scroller.list-detail {
1528
+ --infiniteScrollerRowGap: 24px;
1529
+ }
1530
+
1531
+ infinite-scroller.grid {
1532
+ --infiniteScrollerCellMinWidth: var(
1533
+ --collectionBrowserCellMinWidth,
1534
+ 18rem
1535
+ );
1536
+ --infiniteScrollerCellMaxWidth: var(--collectionBrowserCellMaxWidth, 1fr);
1537
+ --infiniteScrollerCellMinHeight: var(
1538
+ --collectionBrowserCellMinHeight,
1539
+ 29rem
1540
+ );
1541
+ --infiniteScrollerCellMaxHeight: var(
1542
+ --collectionBrowserCellMaxHeight,
1543
+ 29rem
1544
+ );
1545
+ }
1546
+ `;
1547
+ }