@salesforcedevs/dw-components 0.71.0 → 0.72.0
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/package.json +2 -2
- package/src/modules/dw/blogsGrid/blogsGrid.html +1 -1
- package/src/modules/dw/contentArchive/contentArchive.html +6 -6
- package/src/modules/dw/contentArchive/contentArchive.ts +103 -71
- package/src/modules/dw/contentArchive/contentArchive.types.ts +20 -9
- package/src/modules/dw/contentArchive/utils.ts +42 -16
- package/src/modules/dw/podcastsGrid/podcastsGrid.html +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dw-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0",
|
|
4
4
|
"description": "Lightning web components for https://developer.salesforce.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@types/lodash.orderby": "^4.6.7",
|
|
23
23
|
"@types/lodash.uniqby": "^4.7.7"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "fd347f27dc9472a9ead4f35f701b8914ba9f872e"
|
|
26
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}
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
</button>
|
|
75
75
|
</div>
|
|
76
76
|
<dx-filter-menu
|
|
77
|
-
name="
|
|
77
|
+
name="contentType"
|
|
78
78
|
title={contentTypeTitle}
|
|
79
79
|
options={contentTypeList}
|
|
80
80
|
onchange={handleUpdateSiteFilter}
|
|
@@ -158,17 +158,17 @@
|
|
|
158
158
|
</template>
|
|
159
159
|
</div>
|
|
160
160
|
<div class="filter-chips-container">
|
|
161
|
-
<template if:true={selectedFilterMenuData.
|
|
161
|
+
<template if:true={selectedFilterMenuData.contentType.length}>
|
|
162
162
|
<div class="chip-item-container">
|
|
163
163
|
<p class="chip-title">Type</p>
|
|
164
164
|
<template
|
|
165
|
-
for:each={selectedFilterMenuData.
|
|
165
|
+
for:each={selectedFilterMenuData.contentType}
|
|
166
166
|
for:item="postType"
|
|
167
167
|
>
|
|
168
168
|
<span class="chip-item" key={postType.name}>
|
|
169
169
|
{postType.name}
|
|
170
170
|
<dx-button
|
|
171
|
-
name="
|
|
171
|
+
name="contentType"
|
|
172
172
|
value={postType}
|
|
173
173
|
onclick={removeFilterItem}
|
|
174
174
|
variant="inline"
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
for:each={selectedFilterMenuData.dates}
|
|
188
188
|
for:item="date"
|
|
189
189
|
>
|
|
190
|
-
<span class="chip-item" key={date}>
|
|
190
|
+
<span class="chip-item" key={date.name}>
|
|
191
191
|
{date.name}
|
|
192
192
|
<dx-button
|
|
193
193
|
name="dates"
|
|
@@ -2,12 +2,23 @@ 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
|
+
FilterMenuItem
|
|
11
|
+
} from "./contentArchive.types";
|
|
7
12
|
|
|
8
13
|
const MOBILE_MATCH = "767px";
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
enum FilterNames {
|
|
16
|
+
QUERY_CONTENT_FILTER = "contentType",
|
|
17
|
+
QUERY_AUTHOR_FILTER = "authors",
|
|
18
|
+
QUERY_DATES_FILTER = "dates",
|
|
19
|
+
QUERY_CATEGORIES_FILTER = "categories"
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
const PODCASTS = { id: 2, name: "Podcasts" };
|
|
12
23
|
const BLOGS = { id: 1, name: "Blogs" };
|
|
13
24
|
export default class ContentArchive extends LightningElement {
|
|
@@ -22,7 +33,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
22
33
|
private filtersLoading: boolean = true;
|
|
23
34
|
private filtersDatesLoading: boolean = false;
|
|
24
35
|
private modalOpen: boolean = false;
|
|
25
|
-
private cardType:
|
|
36
|
+
private cardType: "expanded" | "minimal" = "expanded";
|
|
26
37
|
|
|
27
38
|
private postsByDate: {} = {};
|
|
28
39
|
private dateList: any[] = [];
|
|
@@ -33,13 +44,18 @@ export default class ContentArchive extends LightningElement {
|
|
|
33
44
|
private mobileMatchMedia!: MediaQueryList;
|
|
34
45
|
|
|
35
46
|
private selectedFilterMenuData: Filters = {
|
|
36
|
-
|
|
47
|
+
contentType: [],
|
|
37
48
|
dates: [],
|
|
38
49
|
authors: [],
|
|
39
50
|
categories: []
|
|
40
51
|
};
|
|
52
|
+
|
|
41
53
|
private posts: any[] = [];
|
|
42
54
|
|
|
55
|
+
get isEmptyState() {
|
|
56
|
+
return this.totalResults === 0 && !this.loading;
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
get currentPageLength() {
|
|
44
60
|
if (this.loading) {
|
|
45
61
|
return "Loading Results...";
|
|
@@ -65,10 +81,6 @@ export default class ContentArchive extends LightningElement {
|
|
|
65
81
|
return this.totalResults ? `Archive Results ${pageInfo}` : "No results";
|
|
66
82
|
}
|
|
67
83
|
|
|
68
|
-
get isEmptyState() {
|
|
69
|
-
return this.totalResults === 0 && !this.loading;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
84
|
get spinnerSize() {
|
|
73
85
|
return this.isMobile ? "medium" : "large";
|
|
74
86
|
}
|
|
@@ -97,15 +109,15 @@ export default class ContentArchive extends LightningElement {
|
|
|
97
109
|
|
|
98
110
|
get hideBlogFilters() {
|
|
99
111
|
return (
|
|
100
|
-
this.selectedFilterMenuData.
|
|
101
|
-
this.selectedFilterMenuData.
|
|
112
|
+
this.selectedFilterMenuData.contentType.length === 1 &&
|
|
113
|
+
this.selectedFilterMenuData.contentType[0].id === 2
|
|
102
114
|
);
|
|
103
115
|
}
|
|
104
116
|
|
|
105
117
|
get contentTypeTitle() {
|
|
106
118
|
return `Content Type ${
|
|
107
|
-
this.selectedFilterMenuData.
|
|
108
|
-
? `(${this.selectedFilterMenuData.
|
|
119
|
+
this.selectedFilterMenuData.contentType.length > 0
|
|
120
|
+
? `(${this.selectedFilterMenuData.contentType.length})`
|
|
109
121
|
: ""
|
|
110
122
|
}`;
|
|
111
123
|
}
|
|
@@ -132,16 +144,16 @@ export default class ContentArchive extends LightningElement {
|
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
get selectedPostType() {
|
|
135
|
-
return this.selectedFilterMenuData.
|
|
136
|
-
? this.selectedFilterMenuData.
|
|
147
|
+
return this.selectedFilterMenuData.contentType.length === 1
|
|
148
|
+
? this.selectedFilterMenuData.contentType[0].name.toLowerCase()
|
|
137
149
|
: "all";
|
|
138
150
|
}
|
|
139
151
|
|
|
140
152
|
private filterSelectedDates(
|
|
141
|
-
currentDateList: Array<{ name: string }>,
|
|
142
153
|
selectedDate: string,
|
|
143
154
|
toRemove: boolean = false
|
|
144
155
|
) {
|
|
156
|
+
const currentDateList = this.selectedFilterMenuData.dates;
|
|
145
157
|
return currentDateList.filter((currentDateItem: { name: string }) => {
|
|
146
158
|
const year = currentDateItem.name.slice(-4);
|
|
147
159
|
|
|
@@ -170,8 +182,6 @@ export default class ContentArchive extends LightningElement {
|
|
|
170
182
|
selectedFilters = null;
|
|
171
183
|
}
|
|
172
184
|
|
|
173
|
-
setUrlParamValue(QUERY_SITE_FILTER, selectedFilters);
|
|
174
|
-
|
|
175
185
|
this.updateSelectedFilters(value, name, checked);
|
|
176
186
|
this.fetchArchiveFilterDateList();
|
|
177
187
|
}
|
|
@@ -183,8 +193,9 @@ export default class ContentArchive extends LightningElement {
|
|
|
183
193
|
|
|
184
194
|
private updateSelectedFilters(
|
|
185
195
|
value: any,
|
|
186
|
-
name:
|
|
187
|
-
checked: any
|
|
196
|
+
name: FilterMenuNames,
|
|
197
|
+
checked: any,
|
|
198
|
+
suppressFetch: boolean = false
|
|
188
199
|
) {
|
|
189
200
|
let copy = {
|
|
190
201
|
...this.selectedFilterMenuData
|
|
@@ -200,26 +211,25 @@ export default class ContentArchive extends LightningElement {
|
|
|
200
211
|
const regex = /^(\d{4})$/g;
|
|
201
212
|
|
|
202
213
|
if (regex.test(value.name) && copy[name].length > 0) {
|
|
203
|
-
copy[name] = this.filterSelectedDates(
|
|
214
|
+
copy[name] = this.filterSelectedDates(value.name);
|
|
204
215
|
} else if (regex.test(value.name.slice(-4))) {
|
|
205
|
-
copy[name] = this.filterSelectedDates(
|
|
206
|
-
copy[name],
|
|
207
|
-
value.name,
|
|
208
|
-
true
|
|
209
|
-
);
|
|
216
|
+
copy[name] = this.filterSelectedDates(value.name, true);
|
|
210
217
|
}
|
|
211
218
|
|
|
212
|
-
copy[name].
|
|
219
|
+
if (!copy[name].find((item) => item.name === value.name)) {
|
|
220
|
+
copy[name].push(value);
|
|
221
|
+
}
|
|
213
222
|
}
|
|
214
223
|
|
|
215
224
|
// Remove filters when only podcast is selected
|
|
216
225
|
if (
|
|
217
|
-
name ===
|
|
226
|
+
name === FilterNames.QUERY_CONTENT_FILTER &&
|
|
218
227
|
copy[name].length === 1 &&
|
|
219
228
|
!copy[name].some((item: { id: number }) => item.id === 1)
|
|
220
229
|
) {
|
|
230
|
+
setUrlParamValue({ QUERY_AUTHOR_FILTER: [] });
|
|
221
231
|
copy = {
|
|
222
|
-
|
|
232
|
+
contentType: [...copy.contentType],
|
|
223
233
|
categories: [...copy.categories],
|
|
224
234
|
dates: [...copy.dates],
|
|
225
235
|
authors: []
|
|
@@ -228,21 +238,26 @@ export default class ContentArchive extends LightningElement {
|
|
|
228
238
|
|
|
229
239
|
// Checkmark the blog type if value is a blog author
|
|
230
240
|
if (name === "authors" && checked) {
|
|
241
|
+
setUrlParamValue({ [FilterNames.QUERY_CONTENT_FILTER]: ["Blogs"] });
|
|
231
242
|
copy = {
|
|
232
|
-
|
|
243
|
+
contentType: [{ id: 1, name: "Blogs" }],
|
|
233
244
|
categories: [...copy.categories],
|
|
234
245
|
dates: [...copy.dates],
|
|
235
246
|
authors: [...copy.authors]
|
|
236
247
|
};
|
|
237
248
|
}
|
|
238
249
|
|
|
250
|
+
setUrlParamValue({ [name]: copy[name].map((a) => a.name) });
|
|
251
|
+
|
|
239
252
|
this.selectedFilterMenuData = copy;
|
|
240
253
|
this.currentPage = 1;
|
|
241
254
|
this.updateCheckedStatus();
|
|
242
|
-
|
|
255
|
+
if (!suppressFetch) {
|
|
256
|
+
this.fetchPostsByCardType();
|
|
257
|
+
}
|
|
243
258
|
}
|
|
244
259
|
|
|
245
|
-
private updateCheckedStatus() {
|
|
260
|
+
private async updateCheckedStatus() {
|
|
246
261
|
const filterMenuElements =
|
|
247
262
|
this.template.querySelectorAll("dx-filter-menu");
|
|
248
263
|
|
|
@@ -301,7 +316,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
301
316
|
|
|
302
317
|
private handleFilterClear() {
|
|
303
318
|
this.selectedFilterMenuData = {
|
|
304
|
-
|
|
319
|
+
contentType: [],
|
|
305
320
|
dates: [],
|
|
306
321
|
authors: [],
|
|
307
322
|
categories: []
|
|
@@ -310,7 +325,12 @@ export default class ContentArchive extends LightningElement {
|
|
|
310
325
|
this.updateCheckedStatus();
|
|
311
326
|
this.fetchPostsByCardType();
|
|
312
327
|
|
|
313
|
-
setUrlParamValue(
|
|
328
|
+
setUrlParamValue({
|
|
329
|
+
[FilterNames.QUERY_CONTENT_FILTER]: [],
|
|
330
|
+
[FilterNames.QUERY_AUTHOR_FILTER]: [],
|
|
331
|
+
[FilterNames.QUERY_CATEGORIES_FILTER]: [],
|
|
332
|
+
[FilterNames.QUERY_DATES_FILTER]: []
|
|
333
|
+
});
|
|
314
334
|
}
|
|
315
335
|
|
|
316
336
|
private goToPage(e: CustomEvent) {
|
|
@@ -342,6 +362,8 @@ export default class ContentArchive extends LightningElement {
|
|
|
342
362
|
this.authorList = authors;
|
|
343
363
|
this.categoryList = categories;
|
|
344
364
|
this.filtersLoading = false;
|
|
365
|
+
|
|
366
|
+
requestAnimationFrame(() => this.updateAllFiltersFromUrl());
|
|
345
367
|
}
|
|
346
368
|
}
|
|
347
369
|
|
|
@@ -358,12 +380,12 @@ export default class ContentArchive extends LightningElement {
|
|
|
358
380
|
private async fetchPosts(numberOfPosts: number) {
|
|
359
381
|
this.loading = true;
|
|
360
382
|
|
|
361
|
-
const { posts, totalResults, totalPages } = await getArchivePosts(
|
|
362
|
-
numberOfPosts,
|
|
363
|
-
this.currentPage,
|
|
364
|
-
this.cardType,
|
|
365
|
-
this.selectedFilterMenuData
|
|
366
|
-
);
|
|
383
|
+
const { posts, totalResults, totalPages } = await getArchivePosts({
|
|
384
|
+
count: numberOfPosts,
|
|
385
|
+
page: this.currentPage,
|
|
386
|
+
contentType: this.cardType,
|
|
387
|
+
filterMenuData: this.selectedFilterMenuData
|
|
388
|
+
});
|
|
367
389
|
|
|
368
390
|
this.posts = posts;
|
|
369
391
|
this.totalResults = totalResults;
|
|
@@ -442,46 +464,56 @@ export default class ContentArchive extends LightningElement {
|
|
|
442
464
|
this.onMobileChange(this.mobileMatchMedia);
|
|
443
465
|
this.mobileMatchMedia.addEventListener("change", this.onMobileChange);
|
|
444
466
|
|
|
445
|
-
const presetFilters: Array<string> =
|
|
446
|
-
getUrlParamValue(QUERY_SITE_FILTER);
|
|
447
|
-
|
|
448
|
-
if (presetFilters.length === 1) {
|
|
449
|
-
if (presetFilters[0] === BLOGS.name) {
|
|
450
|
-
this.presetSiteFilter(BLOGS);
|
|
451
|
-
} else {
|
|
452
|
-
this.presetSiteFilter(PODCASTS);
|
|
453
|
-
}
|
|
454
|
-
} else if (presetFilters.length === 2) {
|
|
455
|
-
this.presetSiteFilter();
|
|
456
|
-
}
|
|
457
|
-
|
|
458
467
|
if (this.posts.length === 0) {
|
|
459
468
|
this.fetchArchiveFilterList();
|
|
460
469
|
this.fetchPostsByCardType();
|
|
461
470
|
}
|
|
462
471
|
}
|
|
463
472
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
473
|
+
private findDateFromList(nameToFind: string, list: FilterMenuItem[]) {
|
|
474
|
+
return (
|
|
475
|
+
list
|
|
476
|
+
.map((item: any) => item.months)
|
|
477
|
+
.flat()
|
|
478
|
+
.find(
|
|
479
|
+
(month) =>
|
|
480
|
+
month.name.toLowerCase() === nameToFind.toLowerCase()
|
|
481
|
+
) ||
|
|
482
|
+
list.find(
|
|
483
|
+
(item: any) =>
|
|
484
|
+
item.name.toLowerCase() === nameToFind.toLowerCase()
|
|
485
|
+
)
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
private updateAllFiltersFromUrl() {
|
|
490
|
+
const filters: FilterMenuData = {
|
|
491
|
+
[FilterNames.QUERY_AUTHOR_FILTER]: this.authorList,
|
|
492
|
+
[FilterNames.QUERY_DATES_FILTER]: this.dateList,
|
|
493
|
+
[FilterNames.QUERY_CATEGORIES_FILTER]: this.categoryList,
|
|
494
|
+
[FilterNames.QUERY_CONTENT_FILTER]: this.contentTypeList
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
for (const [key, items] of Object.entries(filters)) {
|
|
498
|
+
const presetFilter: Array<string> = getUrlParamValue(key);
|
|
499
|
+
|
|
500
|
+
presetFilter.forEach((item) => {
|
|
501
|
+
const value =
|
|
502
|
+
key === "dates"
|
|
503
|
+
? this.findDateFromList(item, items)
|
|
504
|
+
: items.find(
|
|
505
|
+
(i) => i.name.toLowerCase() === item.toLowerCase()
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
if (value) {
|
|
509
|
+
this.updateSelectedFilters(
|
|
510
|
+
value,
|
|
511
|
+
key as FilterMenuNames,
|
|
512
|
+
true,
|
|
513
|
+
true
|
|
514
|
+
);
|
|
482
515
|
}
|
|
483
516
|
});
|
|
484
|
-
this.updateSelectedFilters(filter, "site", true);
|
|
485
517
|
}
|
|
486
518
|
}
|
|
487
519
|
}
|
|
@@ -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,32 @@ 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;
|
|
84
|
+
months?: Array<{
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
shortName: string;
|
|
88
|
+
isYear: boolean;
|
|
89
|
+
numberOfPosts: number;
|
|
90
|
+
}>;
|
|
80
91
|
};
|
|
81
92
|
|
|
82
93
|
export type FilterMenuData = {
|
|
83
|
-
|
|
94
|
+
contentType: Array<FilterMenuItem>;
|
|
84
95
|
dates: Array<FilterMenuItem>;
|
|
85
96
|
categories: Array<FilterMenuItem>;
|
|
86
97
|
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 = [
|
|
@@ -152,10 +170,18 @@ export async function getArchivePosts(
|
|
|
152
170
|
}
|
|
153
171
|
|
|
154
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
|
+
|
|
155
180
|
const response = await fetch(
|
|
156
181
|
`${ARCHIVE_FILTER_LIST_URL}${
|
|
157
182
|
postType !== "all" ? `&post-type=${postType}` : ""
|
|
158
|
-
}
|
|
183
|
+
}`,
|
|
184
|
+
{ signal }
|
|
159
185
|
);
|
|
160
186
|
|
|
161
187
|
if (response.ok) {
|