@salesforcedevs/dw-components 0.68.1 → 0.68.2-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lwc.config.json +0 -1
- package/package.json +2 -3
- package/src/modules/dw/blogsGrid/blogsGrid.html +1 -1
- package/src/modules/dw/contentArchive/contentArchive.html +7 -5
- package/src/modules/dw/contentArchive/contentArchive.ts +105 -72
- package/src/modules/dw/contentArchive/contentArchive.types.ts +13 -9
- package/src/modules/dw/contentArchive/utils.ts +47 -17
- package/src/modules/dw/podcastsGrid/podcastsGrid.html +1 -1
- package/src/modules/dw/searchResults/coveo.css +0 -18989
- package/src/modules/dw/searchResults/searchResults.css +0 -387
- package/src/modules/dw/searchResults/searchResults.html +0 -104
- package/src/modules/dw/searchResults/searchResults.ts +0 -187
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dw-components",
|
|
3
|
-
"version": "0.68.
|
|
3
|
+
"version": "0.68.2-alpha.22+dc9e7409",
|
|
4
4
|
"description": "Lightning web components for https://developer.salesforce.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"classnames": "^2.2.6",
|
|
14
|
-
"coveo-search-ui": "^2.10082.5",
|
|
15
14
|
"lodash.clonedeep": "^4.5.0",
|
|
16
15
|
"lodash.orderby": "^4.6.0",
|
|
17
16
|
"lodash.uniqby": "^4.7.0",
|
|
@@ -23,5 +22,5 @@
|
|
|
23
22
|
"@types/lodash.orderby": "^4.6.7",
|
|
24
23
|
"@types/lodash.uniqby": "^4.7.7"
|
|
25
24
|
},
|
|
26
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "dc9e74091d9f224cc819c9171fe8fb152bfd6a41"
|
|
27
26
|
}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</button>
|
|
27
27
|
</div>
|
|
28
28
|
<dx-filter-menu
|
|
29
|
-
name="
|
|
29
|
+
name="content-type"
|
|
30
30
|
title={contentTypeTitle}
|
|
31
31
|
options={contentTypeList}
|
|
32
32
|
onchange={handleUpdateSiteFilter}
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
title={dateTitle}
|
|
37
37
|
options={dateList}
|
|
38
38
|
variant="nested"
|
|
39
|
+
filters-dates-loading={filtersDatesLoading}
|
|
39
40
|
onchange={handleFiltersEvent}
|
|
40
41
|
></dx-filter-menu>
|
|
41
42
|
<template if:false={hideBlogFilters}>
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
</button>
|
|
74
75
|
</div>
|
|
75
76
|
<dx-filter-menu
|
|
76
|
-
name="
|
|
77
|
+
name="contentType"
|
|
77
78
|
title={contentTypeTitle}
|
|
78
79
|
options={contentTypeList}
|
|
79
80
|
onchange={handleUpdateSiteFilter}
|
|
@@ -82,6 +83,7 @@
|
|
|
82
83
|
name="dates"
|
|
83
84
|
title={dateTitle}
|
|
84
85
|
options={dateList}
|
|
86
|
+
filters-dates-loading={filtersDatesLoading}
|
|
85
87
|
variant="nested"
|
|
86
88
|
onchange={handleFiltersEvent}
|
|
87
89
|
></dx-filter-menu>
|
|
@@ -156,17 +158,17 @@
|
|
|
156
158
|
</template>
|
|
157
159
|
</div>
|
|
158
160
|
<div class="filter-chips-container">
|
|
159
|
-
<template if:true={selectedFilterMenuData.
|
|
161
|
+
<template if:true={selectedFilterMenuData.contentType.length}>
|
|
160
162
|
<div class="chip-item-container">
|
|
161
163
|
<p class="chip-title">Type</p>
|
|
162
164
|
<template
|
|
163
|
-
for:each={selectedFilterMenuData.
|
|
165
|
+
for:each={selectedFilterMenuData.contentType}
|
|
164
166
|
for:item="postType"
|
|
165
167
|
>
|
|
166
168
|
<span class="chip-item" key={postType.name}>
|
|
167
169
|
{postType.name}
|
|
168
170
|
<dx-button
|
|
169
|
-
name="
|
|
171
|
+
name="contentType"
|
|
170
172
|
value={postType}
|
|
171
173
|
onclick={removeFilterItem}
|
|
172
174
|
variant="inline"
|
|
@@ -2,12 +2,22 @@ import { LightningElement } from "lwc";
|
|
|
2
2
|
import cx from "classnames";
|
|
3
3
|
import { PER_PAGE_COUNT, getArchivePosts, getArchiveFilterList } from "./utils";
|
|
4
4
|
import { sortSplittedPostsByMonth } from "dxUtils/dates";
|
|
5
|
-
import { Filters } from "./contentArchive.types";
|
|
6
5
|
import { getUrlParamValue, setUrlParamValue } from "dxUtils/queryCoordinator";
|
|
6
|
+
import {
|
|
7
|
+
Filters,
|
|
8
|
+
FilterMenuData,
|
|
9
|
+
FilterMenuNames
|
|
10
|
+
} from "./contentArchive.types";
|
|
7
11
|
|
|
8
12
|
const MOBILE_MATCH = "767px";
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
enum FilterNames {
|
|
15
|
+
QUERY_CONTENT_FILTER = "contentType",
|
|
16
|
+
QUERY_AUTHOR_FILTER = "authors",
|
|
17
|
+
QUERY_DATES_FILTER = "dates",
|
|
18
|
+
QUERY_CATEGORIES_FILTER = "categories"
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
const PODCASTS = { id: 2, name: "Podcasts" };
|
|
12
22
|
const BLOGS = { id: 1, name: "Blogs" };
|
|
13
23
|
export default class ContentArchive extends LightningElement {
|
|
@@ -20,8 +30,9 @@ export default class ContentArchive extends LightningElement {
|
|
|
20
30
|
private totalPages: number = 1;
|
|
21
31
|
private loading: boolean = true;
|
|
22
32
|
private filtersLoading: boolean = true;
|
|
33
|
+
private filtersDatesLoading: boolean = false;
|
|
23
34
|
private modalOpen: boolean = false;
|
|
24
|
-
private cardType:
|
|
35
|
+
private cardType: "expanded" | "minimal" = "expanded";
|
|
25
36
|
|
|
26
37
|
private postsByDate: {} = {};
|
|
27
38
|
private dateList: any[] = [];
|
|
@@ -32,13 +43,18 @@ export default class ContentArchive extends LightningElement {
|
|
|
32
43
|
private mobileMatchMedia!: MediaQueryList;
|
|
33
44
|
|
|
34
45
|
private selectedFilterMenuData: Filters = {
|
|
35
|
-
|
|
46
|
+
contentType: [],
|
|
36
47
|
dates: [],
|
|
37
48
|
authors: [],
|
|
38
49
|
categories: []
|
|
39
50
|
};
|
|
51
|
+
|
|
40
52
|
private posts: any[] = [];
|
|
41
53
|
|
|
54
|
+
get isEmptyState() {
|
|
55
|
+
return this.totalResults === 0 && !this.loading;
|
|
56
|
+
}
|
|
57
|
+
|
|
42
58
|
get currentPageLength() {
|
|
43
59
|
if (this.loading) {
|
|
44
60
|
return "Loading Results...";
|
|
@@ -64,10 +80,6 @@ export default class ContentArchive extends LightningElement {
|
|
|
64
80
|
return this.totalResults ? `Archive Results ${pageInfo}` : "No results";
|
|
65
81
|
}
|
|
66
82
|
|
|
67
|
-
get isEmptyState() {
|
|
68
|
-
return this.totalResults === 0 && !this.loading;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
83
|
get spinnerSize() {
|
|
72
84
|
return this.isMobile ? "medium" : "large";
|
|
73
85
|
}
|
|
@@ -96,15 +108,15 @@ export default class ContentArchive extends LightningElement {
|
|
|
96
108
|
|
|
97
109
|
get hideBlogFilters() {
|
|
98
110
|
return (
|
|
99
|
-
this.selectedFilterMenuData.
|
|
100
|
-
this.selectedFilterMenuData.
|
|
111
|
+
this.selectedFilterMenuData.contentType.length === 1 &&
|
|
112
|
+
this.selectedFilterMenuData.contentType[0].id === 2
|
|
101
113
|
);
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
get contentTypeTitle() {
|
|
105
117
|
return `Content Type ${
|
|
106
|
-
this.selectedFilterMenuData.
|
|
107
|
-
? `(${this.selectedFilterMenuData.
|
|
118
|
+
this.selectedFilterMenuData.contentType.length > 0
|
|
119
|
+
? `(${this.selectedFilterMenuData.contentType.length})`
|
|
108
120
|
: ""
|
|
109
121
|
}`;
|
|
110
122
|
}
|
|
@@ -130,11 +142,17 @@ export default class ContentArchive extends LightningElement {
|
|
|
130
142
|
}`;
|
|
131
143
|
}
|
|
132
144
|
|
|
145
|
+
get selectedPostType() {
|
|
146
|
+
return this.selectedFilterMenuData.contentType.length === 1
|
|
147
|
+
? this.selectedFilterMenuData.contentType[0].name.toLowerCase()
|
|
148
|
+
: "all";
|
|
149
|
+
}
|
|
150
|
+
|
|
133
151
|
private filterSelectedDates(
|
|
134
|
-
currentDateList: Array<{ name: string }>,
|
|
135
152
|
selectedDate: string,
|
|
136
153
|
toRemove: boolean = false
|
|
137
154
|
) {
|
|
155
|
+
const currentDateList = this.selectedFilterMenuData.dates;
|
|
138
156
|
return currentDateList.filter((currentDateItem: { name: string }) => {
|
|
139
157
|
const year = currentDateItem.name.slice(-4);
|
|
140
158
|
|
|
@@ -163,9 +181,8 @@ export default class ContentArchive extends LightningElement {
|
|
|
163
181
|
selectedFilters = null;
|
|
164
182
|
}
|
|
165
183
|
|
|
166
|
-
setUrlParamValue(QUERY_SITE_FILTER, selectedFilters);
|
|
167
|
-
|
|
168
184
|
this.updateSelectedFilters(value, name, checked);
|
|
185
|
+
this.fetchArchiveFilterDateList();
|
|
169
186
|
}
|
|
170
187
|
|
|
171
188
|
private handleFiltersEvent(e: CustomEvent) {
|
|
@@ -175,8 +192,9 @@ export default class ContentArchive extends LightningElement {
|
|
|
175
192
|
|
|
176
193
|
private updateSelectedFilters(
|
|
177
194
|
value: any,
|
|
178
|
-
name:
|
|
179
|
-
checked: any
|
|
195
|
+
name: FilterMenuNames,
|
|
196
|
+
checked: any,
|
|
197
|
+
suppressFetch: boolean = false
|
|
180
198
|
) {
|
|
181
199
|
let copy = {
|
|
182
200
|
...this.selectedFilterMenuData
|
|
@@ -192,26 +210,25 @@ export default class ContentArchive extends LightningElement {
|
|
|
192
210
|
const regex = /^(\d{4})$/g;
|
|
193
211
|
|
|
194
212
|
if (regex.test(value.name) && copy[name].length > 0) {
|
|
195
|
-
copy[name] = this.filterSelectedDates(
|
|
213
|
+
copy[name] = this.filterSelectedDates(value.name);
|
|
196
214
|
} else if (regex.test(value.name.slice(-4))) {
|
|
197
|
-
copy[name] = this.filterSelectedDates(
|
|
198
|
-
copy[name],
|
|
199
|
-
value.name,
|
|
200
|
-
true
|
|
201
|
-
);
|
|
215
|
+
copy[name] = this.filterSelectedDates(value.name, true);
|
|
202
216
|
}
|
|
203
217
|
|
|
204
|
-
copy[name].
|
|
218
|
+
if (!copy[name].find((item) => item.name === value.name)) {
|
|
219
|
+
copy[name].push(value);
|
|
220
|
+
}
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
// Remove filters when only podcast is selected
|
|
208
224
|
if (
|
|
209
|
-
name ===
|
|
225
|
+
name === FilterNames.QUERY_CONTENT_FILTER &&
|
|
210
226
|
copy[name].length === 1 &&
|
|
211
227
|
!copy[name].some((item: { id: number }) => item.id === 1)
|
|
212
228
|
) {
|
|
229
|
+
setUrlParamValue({ QUERY_AUTHOR_FILTER: [] });
|
|
213
230
|
copy = {
|
|
214
|
-
|
|
231
|
+
contentType: [...copy.contentType],
|
|
215
232
|
categories: [...copy.categories],
|
|
216
233
|
dates: [...copy.dates],
|
|
217
234
|
authors: []
|
|
@@ -220,21 +237,26 @@ export default class ContentArchive extends LightningElement {
|
|
|
220
237
|
|
|
221
238
|
// Checkmark the blog type if value is a blog author
|
|
222
239
|
if (name === "authors" && checked) {
|
|
240
|
+
setUrlParamValue({ [FilterNames.QUERY_CONTENT_FILTER]: ["Blogs"] });
|
|
223
241
|
copy = {
|
|
224
|
-
|
|
242
|
+
contentType: [{ id: 1, name: "Blogs" }],
|
|
225
243
|
categories: [...copy.categories],
|
|
226
244
|
dates: [...copy.dates],
|
|
227
245
|
authors: [...copy.authors]
|
|
228
246
|
};
|
|
229
247
|
}
|
|
230
248
|
|
|
249
|
+
setUrlParamValue({ [name]: copy[name].map((a) => a.name) });
|
|
250
|
+
|
|
231
251
|
this.selectedFilterMenuData = copy;
|
|
232
252
|
this.currentPage = 1;
|
|
233
253
|
this.updateCheckedStatus();
|
|
234
|
-
|
|
254
|
+
if (!suppressFetch) {
|
|
255
|
+
this.fetchPostsByCardType();
|
|
256
|
+
}
|
|
235
257
|
}
|
|
236
258
|
|
|
237
|
-
private updateCheckedStatus() {
|
|
259
|
+
private async updateCheckedStatus() {
|
|
238
260
|
const filterMenuElements =
|
|
239
261
|
this.template.querySelectorAll("dx-filter-menu");
|
|
240
262
|
|
|
@@ -293,7 +315,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
293
315
|
|
|
294
316
|
private handleFilterClear() {
|
|
295
317
|
this.selectedFilterMenuData = {
|
|
296
|
-
|
|
318
|
+
contentType: [],
|
|
297
319
|
dates: [],
|
|
298
320
|
authors: [],
|
|
299
321
|
categories: []
|
|
@@ -302,7 +324,12 @@ export default class ContentArchive extends LightningElement {
|
|
|
302
324
|
this.updateCheckedStatus();
|
|
303
325
|
this.fetchPostsByCardType();
|
|
304
326
|
|
|
305
|
-
setUrlParamValue(
|
|
327
|
+
setUrlParamValue({
|
|
328
|
+
[FilterNames.QUERY_CONTENT_FILTER]: [],
|
|
329
|
+
[FilterNames.QUERY_AUTHOR_FILTER]: [],
|
|
330
|
+
[FilterNames.QUERY_CATEGORIES_FILTER]: [],
|
|
331
|
+
[FilterNames.QUERY_DATES_FILTER]: []
|
|
332
|
+
});
|
|
306
333
|
}
|
|
307
334
|
|
|
308
335
|
private goToPage(e: CustomEvent) {
|
|
@@ -314,7 +341,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
314
341
|
this.fetchPostsByCardType();
|
|
315
342
|
}
|
|
316
343
|
|
|
317
|
-
private fetchPostsByCardType() {
|
|
344
|
+
private async fetchPostsByCardType() {
|
|
318
345
|
if (this.cardType === "minimal") {
|
|
319
346
|
this.fetchPosts(20);
|
|
320
347
|
} else {
|
|
@@ -325,24 +352,39 @@ export default class ContentArchive extends LightningElement {
|
|
|
325
352
|
private async fetchArchiveFilterList() {
|
|
326
353
|
if (!this.dateList.length) {
|
|
327
354
|
this.filtersLoading = true;
|
|
328
|
-
|
|
355
|
+
|
|
356
|
+
const { dates, authors, categories } = await getArchiveFilterList(
|
|
357
|
+
this.selectedPostType
|
|
358
|
+
);
|
|
329
359
|
|
|
330
360
|
this.dateList = this.splitOptionsByDate(dates);
|
|
331
361
|
this.authorList = authors;
|
|
332
362
|
this.categoryList = categories;
|
|
333
363
|
this.filtersLoading = false;
|
|
364
|
+
|
|
365
|
+
requestAnimationFrame(() => this.updateAllFiltersFromUrl());
|
|
334
366
|
}
|
|
335
367
|
}
|
|
336
368
|
|
|
369
|
+
private async fetchArchiveFilterDateList() {
|
|
370
|
+
this.filtersDatesLoading = true;
|
|
371
|
+
|
|
372
|
+
const { dates } = await getArchiveFilterList(this.selectedPostType);
|
|
373
|
+
|
|
374
|
+
this.dateList = this.splitOptionsByDate(dates);
|
|
375
|
+
|
|
376
|
+
this.filtersDatesLoading = false;
|
|
377
|
+
}
|
|
378
|
+
|
|
337
379
|
private async fetchPosts(numberOfPosts: number) {
|
|
338
380
|
this.loading = true;
|
|
339
381
|
|
|
340
|
-
const { posts, totalResults, totalPages } = await getArchivePosts(
|
|
341
|
-
numberOfPosts,
|
|
342
|
-
this.currentPage,
|
|
343
|
-
this.cardType,
|
|
344
|
-
this.selectedFilterMenuData
|
|
345
|
-
);
|
|
382
|
+
const { posts, totalResults, totalPages } = await getArchivePosts({
|
|
383
|
+
count: numberOfPosts,
|
|
384
|
+
page: this.currentPage,
|
|
385
|
+
contentType: this.cardType,
|
|
386
|
+
filterMenuData: this.selectedFilterMenuData
|
|
387
|
+
});
|
|
346
388
|
|
|
347
389
|
this.posts = posts;
|
|
348
390
|
this.totalResults = totalResults;
|
|
@@ -414,53 +456,44 @@ export default class ContentArchive extends LightningElement {
|
|
|
414
456
|
requestAnimationFrame(() => this.updateCheckedStatus());
|
|
415
457
|
};
|
|
416
458
|
|
|
417
|
-
connectedCallback(): void {
|
|
459
|
+
async connectedCallback(): Promise<void> {
|
|
418
460
|
this.mobileMatchMedia = window.matchMedia(
|
|
419
461
|
`(max-width: ${MOBILE_MATCH})`
|
|
420
462
|
);
|
|
421
463
|
this.onMobileChange(this.mobileMatchMedia);
|
|
422
464
|
this.mobileMatchMedia.addEventListener("change", this.onMobileChange);
|
|
423
465
|
|
|
424
|
-
const presetFilters: Array<string> =
|
|
425
|
-
getUrlParamValue(QUERY_SITE_FILTER);
|
|
426
|
-
|
|
427
|
-
if (presetFilters.length === 1) {
|
|
428
|
-
if (presetFilters[0] === BLOGS.name) {
|
|
429
|
-
this.presetSiteFilter(BLOGS);
|
|
430
|
-
} else {
|
|
431
|
-
this.presetSiteFilter(PODCASTS);
|
|
432
|
-
}
|
|
433
|
-
} else if (presetFilters.length === 2) {
|
|
434
|
-
this.presetSiteFilter();
|
|
435
|
-
}
|
|
436
|
-
|
|
437
466
|
if (this.posts.length === 0) {
|
|
438
467
|
this.fetchArchiveFilterList();
|
|
439
468
|
this.fetchPostsByCardType();
|
|
440
469
|
}
|
|
441
470
|
}
|
|
442
471
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
this.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
472
|
+
private updateAllFiltersFromUrl() {
|
|
473
|
+
const filters: FilterMenuData = {
|
|
474
|
+
[FilterNames.QUERY_AUTHOR_FILTER]: this.authorList,
|
|
475
|
+
[FilterNames.QUERY_DATES_FILTER]: this.dateList,
|
|
476
|
+
[FilterNames.QUERY_CATEGORIES_FILTER]: this.categoryList,
|
|
477
|
+
[FilterNames.QUERY_CONTENT_FILTER]: this.contentTypeList
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
for (const [key, items] of Object.entries(filters)) {
|
|
481
|
+
const presetFilter: Array<string> = getUrlParamValue(key);
|
|
482
|
+
|
|
483
|
+
presetFilter.forEach((item) => {
|
|
484
|
+
const value = items.find(
|
|
485
|
+
(i) => i.name.toLowerCase() === item.toLowerCase()
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
if (value) {
|
|
489
|
+
this.updateSelectedFilters(
|
|
490
|
+
value,
|
|
491
|
+
key as FilterMenuNames,
|
|
492
|
+
true,
|
|
493
|
+
true
|
|
494
|
+
);
|
|
461
495
|
}
|
|
462
496
|
});
|
|
463
|
-
this.updateSelectedFilters(filter, "site", true);
|
|
464
497
|
}
|
|
465
498
|
}
|
|
466
499
|
}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export interface Filters {
|
|
2
|
-
site: any[];
|
|
3
|
-
dates: any[];
|
|
4
|
-
authors: any[];
|
|
5
|
-
categories: any[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
1
|
export type ArchivePostAuthor = {
|
|
9
2
|
id: number;
|
|
10
3
|
link: string;
|
|
@@ -73,14 +66,25 @@ export type ArchiveContent = {
|
|
|
73
66
|
totalPages: number;
|
|
74
67
|
};
|
|
75
68
|
|
|
69
|
+
export type FilterMenuNames =
|
|
70
|
+
| "contentType"
|
|
71
|
+
| "dates"
|
|
72
|
+
| "authors"
|
|
73
|
+
| "categories";
|
|
74
|
+
|
|
75
|
+
export type Filters = {
|
|
76
|
+
[key in FilterMenuNames]: any[];
|
|
77
|
+
};
|
|
78
|
+
|
|
76
79
|
export type FilterMenuItem = {
|
|
77
|
-
id: string;
|
|
80
|
+
id: string | number;
|
|
78
81
|
name: string;
|
|
79
82
|
shortName?: string;
|
|
83
|
+
checked?: boolean;
|
|
80
84
|
};
|
|
81
85
|
|
|
82
86
|
export type FilterMenuData = {
|
|
83
|
-
|
|
87
|
+
contentType: Array<FilterMenuItem>;
|
|
84
88
|
dates: Array<FilterMenuItem>;
|
|
85
89
|
categories: Array<FilterMenuItem>;
|
|
86
90
|
authors: Array<FilterMenuItem>;
|
|
@@ -2,11 +2,13 @@ import qs from "query-string";
|
|
|
2
2
|
import {
|
|
3
3
|
ArchivePost,
|
|
4
4
|
ArchivePostNormalized,
|
|
5
|
-
FilterMenuData
|
|
5
|
+
FilterMenuData,
|
|
6
|
+
FilterMenuItem
|
|
6
7
|
} from "./contentArchive.types";
|
|
7
8
|
import altData from "./altData.js";
|
|
8
9
|
|
|
9
|
-
let
|
|
10
|
+
let postsController: AbortController | null = null;
|
|
11
|
+
let filtersController: AbortController | null = null;
|
|
10
12
|
|
|
11
13
|
const ARCHIVE_BASE_URL = "https://developer.salesforce.com/blogs/wp-json/wp/v2";
|
|
12
14
|
const ARCHIVE_CONTENT_URL = `${ARCHIVE_BASE_URL}/latest-post-per-site`;
|
|
@@ -14,12 +16,12 @@ const ARCHIVE_FILTER_LIST_URL = `${ARCHIVE_BASE_URL}/archives-filters?order=DESC
|
|
|
14
16
|
export const PER_PAGE_COUNT = 10;
|
|
15
17
|
|
|
16
18
|
async function postsFetchHandler(url: string) {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
+
if (postsController) {
|
|
20
|
+
postsController.abort();
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
const { signal } =
|
|
23
|
+
postsController = new AbortController();
|
|
24
|
+
const { signal } = postsController;
|
|
23
25
|
|
|
24
26
|
const response = await fetch(url, { signal });
|
|
25
27
|
|
|
@@ -75,19 +77,35 @@ function normalizePosts(posts: Array<ArchivePost>, contentType: string) {
|
|
|
75
77
|
}));
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
export async function getArchivePosts(
|
|
80
|
+
export async function getArchivePosts({
|
|
79
81
|
count = PER_PAGE_COUNT,
|
|
80
|
-
page
|
|
81
|
-
contentType
|
|
82
|
-
filterMenuData
|
|
83
|
-
|
|
82
|
+
page = 1,
|
|
83
|
+
contentType = "minimal",
|
|
84
|
+
filterMenuData = {
|
|
85
|
+
contentType: [],
|
|
86
|
+
dates: [],
|
|
87
|
+
authors: [],
|
|
88
|
+
categories: []
|
|
89
|
+
}
|
|
90
|
+
}: {
|
|
91
|
+
count: number;
|
|
92
|
+
page: number;
|
|
93
|
+
contentType: "minimal" | "expanded";
|
|
94
|
+
filterMenuData: FilterMenuData;
|
|
95
|
+
}): Promise<ArchivePostNormalized> {
|
|
84
96
|
const filterQuery = {
|
|
85
|
-
site: filterMenuData.
|
|
86
|
-
|
|
97
|
+
site: filterMenuData.contentType.map(
|
|
98
|
+
(siteType: FilterMenuItem) => siteType.id
|
|
99
|
+
),
|
|
100
|
+
dates: filterMenuData.dates.map((date: FilterMenuItem) =>
|
|
87
101
|
date.shortName ? date.shortName : date.id
|
|
88
102
|
),
|
|
89
|
-
author: filterMenuData.authors.map(
|
|
90
|
-
|
|
103
|
+
author: filterMenuData.authors.map(
|
|
104
|
+
(author: FilterMenuItem) => author.id
|
|
105
|
+
),
|
|
106
|
+
category: filterMenuData.categories.map(
|
|
107
|
+
(category: FilterMenuItem) => category.id
|
|
108
|
+
)
|
|
91
109
|
};
|
|
92
110
|
|
|
93
111
|
const COMMON_FIELDS = [
|
|
@@ -151,8 +169,20 @@ export async function getArchivePosts(
|
|
|
151
169
|
};
|
|
152
170
|
}
|
|
153
171
|
|
|
154
|
-
export async function getArchiveFilterList() {
|
|
155
|
-
|
|
172
|
+
export async function getArchiveFilterList(postType: string = "all") {
|
|
173
|
+
if (filtersController) {
|
|
174
|
+
filtersController.abort();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
filtersController = new AbortController();
|
|
178
|
+
const { signal } = filtersController;
|
|
179
|
+
|
|
180
|
+
const response = await fetch(
|
|
181
|
+
`${ARCHIVE_FILTER_LIST_URL}${
|
|
182
|
+
postType !== "all" ? `&post-type=${postType}` : ""
|
|
183
|
+
}`,
|
|
184
|
+
{ signal }
|
|
185
|
+
);
|
|
156
186
|
|
|
157
187
|
if (response.ok) {
|
|
158
188
|
return response.json();
|