@salesforcedevs/dw-components 0.70.2 → 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 +8 -6
- package/src/modules/dw/contentArchive/contentArchive.ts +123 -70
- package/src/modules/dw/contentArchive/contentArchive.types.ts +20 -9
- package/src/modules/dw/contentArchive/utils.ts +47 -17
- package/src/modules/dw/deSignupForm/deSignupForm.html +1 -1
- 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}
|
|
@@ -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"
|
|
@@ -185,7 +187,7 @@
|
|
|
185
187
|
for:each={selectedFilterMenuData.dates}
|
|
186
188
|
for:item="date"
|
|
187
189
|
>
|
|
188
|
-
<span class="chip-item" key={date}>
|
|
190
|
+
<span class="chip-item" key={date.name}>
|
|
189
191
|
{date.name}
|
|
190
192
|
<dx-button
|
|
191
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 {
|
|
@@ -20,8 +31,9 @@ export default class ContentArchive extends LightningElement {
|
|
|
20
31
|
private totalPages: number = 1;
|
|
21
32
|
private loading: boolean = true;
|
|
22
33
|
private filtersLoading: boolean = true;
|
|
34
|
+
private filtersDatesLoading: boolean = false;
|
|
23
35
|
private modalOpen: boolean = false;
|
|
24
|
-
private cardType:
|
|
36
|
+
private cardType: "expanded" | "minimal" = "expanded";
|
|
25
37
|
|
|
26
38
|
private postsByDate: {} = {};
|
|
27
39
|
private dateList: any[] = [];
|
|
@@ -32,13 +44,18 @@ export default class ContentArchive extends LightningElement {
|
|
|
32
44
|
private mobileMatchMedia!: MediaQueryList;
|
|
33
45
|
|
|
34
46
|
private selectedFilterMenuData: Filters = {
|
|
35
|
-
|
|
47
|
+
contentType: [],
|
|
36
48
|
dates: [],
|
|
37
49
|
authors: [],
|
|
38
50
|
categories: []
|
|
39
51
|
};
|
|
52
|
+
|
|
40
53
|
private posts: any[] = [];
|
|
41
54
|
|
|
55
|
+
get isEmptyState() {
|
|
56
|
+
return this.totalResults === 0 && !this.loading;
|
|
57
|
+
}
|
|
58
|
+
|
|
42
59
|
get currentPageLength() {
|
|
43
60
|
if (this.loading) {
|
|
44
61
|
return "Loading Results...";
|
|
@@ -64,10 +81,6 @@ export default class ContentArchive extends LightningElement {
|
|
|
64
81
|
return this.totalResults ? `Archive Results ${pageInfo}` : "No results";
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
get isEmptyState() {
|
|
68
|
-
return this.totalResults === 0 && !this.loading;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
84
|
get spinnerSize() {
|
|
72
85
|
return this.isMobile ? "medium" : "large";
|
|
73
86
|
}
|
|
@@ -96,15 +109,15 @@ export default class ContentArchive extends LightningElement {
|
|
|
96
109
|
|
|
97
110
|
get hideBlogFilters() {
|
|
98
111
|
return (
|
|
99
|
-
this.selectedFilterMenuData.
|
|
100
|
-
this.selectedFilterMenuData.
|
|
112
|
+
this.selectedFilterMenuData.contentType.length === 1 &&
|
|
113
|
+
this.selectedFilterMenuData.contentType[0].id === 2
|
|
101
114
|
);
|
|
102
115
|
}
|
|
103
116
|
|
|
104
117
|
get contentTypeTitle() {
|
|
105
118
|
return `Content Type ${
|
|
106
|
-
this.selectedFilterMenuData.
|
|
107
|
-
? `(${this.selectedFilterMenuData.
|
|
119
|
+
this.selectedFilterMenuData.contentType.length > 0
|
|
120
|
+
? `(${this.selectedFilterMenuData.contentType.length})`
|
|
108
121
|
: ""
|
|
109
122
|
}`;
|
|
110
123
|
}
|
|
@@ -130,11 +143,17 @@ export default class ContentArchive extends LightningElement {
|
|
|
130
143
|
}`;
|
|
131
144
|
}
|
|
132
145
|
|
|
146
|
+
get selectedPostType() {
|
|
147
|
+
return this.selectedFilterMenuData.contentType.length === 1
|
|
148
|
+
? this.selectedFilterMenuData.contentType[0].name.toLowerCase()
|
|
149
|
+
: "all";
|
|
150
|
+
}
|
|
151
|
+
|
|
133
152
|
private filterSelectedDates(
|
|
134
|
-
currentDateList: Array<{ name: string }>,
|
|
135
153
|
selectedDate: string,
|
|
136
154
|
toRemove: boolean = false
|
|
137
155
|
) {
|
|
156
|
+
const currentDateList = this.selectedFilterMenuData.dates;
|
|
138
157
|
return currentDateList.filter((currentDateItem: { name: string }) => {
|
|
139
158
|
const year = currentDateItem.name.slice(-4);
|
|
140
159
|
|
|
@@ -163,9 +182,8 @@ export default class ContentArchive extends LightningElement {
|
|
|
163
182
|
selectedFilters = null;
|
|
164
183
|
}
|
|
165
184
|
|
|
166
|
-
setUrlParamValue(QUERY_SITE_FILTER, selectedFilters);
|
|
167
|
-
|
|
168
185
|
this.updateSelectedFilters(value, name, checked);
|
|
186
|
+
this.fetchArchiveFilterDateList();
|
|
169
187
|
}
|
|
170
188
|
|
|
171
189
|
private handleFiltersEvent(e: CustomEvent) {
|
|
@@ -175,8 +193,9 @@ export default class ContentArchive extends LightningElement {
|
|
|
175
193
|
|
|
176
194
|
private updateSelectedFilters(
|
|
177
195
|
value: any,
|
|
178
|
-
name:
|
|
179
|
-
checked: any
|
|
196
|
+
name: FilterMenuNames,
|
|
197
|
+
checked: any,
|
|
198
|
+
suppressFetch: boolean = false
|
|
180
199
|
) {
|
|
181
200
|
let copy = {
|
|
182
201
|
...this.selectedFilterMenuData
|
|
@@ -192,26 +211,25 @@ export default class ContentArchive extends LightningElement {
|
|
|
192
211
|
const regex = /^(\d{4})$/g;
|
|
193
212
|
|
|
194
213
|
if (regex.test(value.name) && copy[name].length > 0) {
|
|
195
|
-
copy[name] = this.filterSelectedDates(
|
|
214
|
+
copy[name] = this.filterSelectedDates(value.name);
|
|
196
215
|
} else if (regex.test(value.name.slice(-4))) {
|
|
197
|
-
copy[name] = this.filterSelectedDates(
|
|
198
|
-
copy[name],
|
|
199
|
-
value.name,
|
|
200
|
-
true
|
|
201
|
-
);
|
|
216
|
+
copy[name] = this.filterSelectedDates(value.name, true);
|
|
202
217
|
}
|
|
203
218
|
|
|
204
|
-
copy[name].
|
|
219
|
+
if (!copy[name].find((item) => item.name === value.name)) {
|
|
220
|
+
copy[name].push(value);
|
|
221
|
+
}
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
// Remove filters when only podcast is selected
|
|
208
225
|
if (
|
|
209
|
-
name ===
|
|
226
|
+
name === FilterNames.QUERY_CONTENT_FILTER &&
|
|
210
227
|
copy[name].length === 1 &&
|
|
211
228
|
!copy[name].some((item: { id: number }) => item.id === 1)
|
|
212
229
|
) {
|
|
230
|
+
setUrlParamValue({ QUERY_AUTHOR_FILTER: [] });
|
|
213
231
|
copy = {
|
|
214
|
-
|
|
232
|
+
contentType: [...copy.contentType],
|
|
215
233
|
categories: [...copy.categories],
|
|
216
234
|
dates: [...copy.dates],
|
|
217
235
|
authors: []
|
|
@@ -220,21 +238,26 @@ export default class ContentArchive extends LightningElement {
|
|
|
220
238
|
|
|
221
239
|
// Checkmark the blog type if value is a blog author
|
|
222
240
|
if (name === "authors" && checked) {
|
|
241
|
+
setUrlParamValue({ [FilterNames.QUERY_CONTENT_FILTER]: ["Blogs"] });
|
|
223
242
|
copy = {
|
|
224
|
-
|
|
243
|
+
contentType: [{ id: 1, name: "Blogs" }],
|
|
225
244
|
categories: [...copy.categories],
|
|
226
245
|
dates: [...copy.dates],
|
|
227
246
|
authors: [...copy.authors]
|
|
228
247
|
};
|
|
229
248
|
}
|
|
230
249
|
|
|
250
|
+
setUrlParamValue({ [name]: copy[name].map((a) => a.name) });
|
|
251
|
+
|
|
231
252
|
this.selectedFilterMenuData = copy;
|
|
232
253
|
this.currentPage = 1;
|
|
233
254
|
this.updateCheckedStatus();
|
|
234
|
-
|
|
255
|
+
if (!suppressFetch) {
|
|
256
|
+
this.fetchPostsByCardType();
|
|
257
|
+
}
|
|
235
258
|
}
|
|
236
259
|
|
|
237
|
-
private updateCheckedStatus() {
|
|
260
|
+
private async updateCheckedStatus() {
|
|
238
261
|
const filterMenuElements =
|
|
239
262
|
this.template.querySelectorAll("dx-filter-menu");
|
|
240
263
|
|
|
@@ -293,7 +316,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
293
316
|
|
|
294
317
|
private handleFilterClear() {
|
|
295
318
|
this.selectedFilterMenuData = {
|
|
296
|
-
|
|
319
|
+
contentType: [],
|
|
297
320
|
dates: [],
|
|
298
321
|
authors: [],
|
|
299
322
|
categories: []
|
|
@@ -302,7 +325,12 @@ export default class ContentArchive extends LightningElement {
|
|
|
302
325
|
this.updateCheckedStatus();
|
|
303
326
|
this.fetchPostsByCardType();
|
|
304
327
|
|
|
305
|
-
setUrlParamValue(
|
|
328
|
+
setUrlParamValue({
|
|
329
|
+
[FilterNames.QUERY_CONTENT_FILTER]: [],
|
|
330
|
+
[FilterNames.QUERY_AUTHOR_FILTER]: [],
|
|
331
|
+
[FilterNames.QUERY_CATEGORIES_FILTER]: [],
|
|
332
|
+
[FilterNames.QUERY_DATES_FILTER]: []
|
|
333
|
+
});
|
|
306
334
|
}
|
|
307
335
|
|
|
308
336
|
private goToPage(e: CustomEvent) {
|
|
@@ -325,24 +353,39 @@ export default class ContentArchive extends LightningElement {
|
|
|
325
353
|
private async fetchArchiveFilterList() {
|
|
326
354
|
if (!this.dateList.length) {
|
|
327
355
|
this.filtersLoading = true;
|
|
328
|
-
|
|
356
|
+
|
|
357
|
+
const { dates, authors, categories } = await getArchiveFilterList(
|
|
358
|
+
this.selectedPostType
|
|
359
|
+
);
|
|
329
360
|
|
|
330
361
|
this.dateList = this.splitOptionsByDate(dates);
|
|
331
362
|
this.authorList = authors;
|
|
332
363
|
this.categoryList = categories;
|
|
333
364
|
this.filtersLoading = false;
|
|
365
|
+
|
|
366
|
+
requestAnimationFrame(() => this.updateAllFiltersFromUrl());
|
|
334
367
|
}
|
|
335
368
|
}
|
|
336
369
|
|
|
370
|
+
private async fetchArchiveFilterDateList() {
|
|
371
|
+
this.filtersDatesLoading = true;
|
|
372
|
+
|
|
373
|
+
const { dates } = await getArchiveFilterList(this.selectedPostType);
|
|
374
|
+
|
|
375
|
+
this.dateList = this.splitOptionsByDate(dates);
|
|
376
|
+
|
|
377
|
+
this.filtersDatesLoading = false;
|
|
378
|
+
}
|
|
379
|
+
|
|
337
380
|
private async fetchPosts(numberOfPosts: number) {
|
|
338
381
|
this.loading = true;
|
|
339
382
|
|
|
340
|
-
const { posts, totalResults, totalPages } = await getArchivePosts(
|
|
341
|
-
numberOfPosts,
|
|
342
|
-
this.currentPage,
|
|
343
|
-
this.cardType,
|
|
344
|
-
this.selectedFilterMenuData
|
|
345
|
-
);
|
|
383
|
+
const { posts, totalResults, totalPages } = await getArchivePosts({
|
|
384
|
+
count: numberOfPosts,
|
|
385
|
+
page: this.currentPage,
|
|
386
|
+
contentType: this.cardType,
|
|
387
|
+
filterMenuData: this.selectedFilterMenuData
|
|
388
|
+
});
|
|
346
389
|
|
|
347
390
|
this.posts = posts;
|
|
348
391
|
this.totalResults = totalResults;
|
|
@@ -421,46 +464,56 @@ export default class ContentArchive extends LightningElement {
|
|
|
421
464
|
this.onMobileChange(this.mobileMatchMedia);
|
|
422
465
|
this.mobileMatchMedia.addEventListener("change", this.onMobileChange);
|
|
423
466
|
|
|
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
467
|
if (this.posts.length === 0) {
|
|
438
468
|
this.fetchArchiveFilterList();
|
|
439
469
|
this.fetchPostsByCardType();
|
|
440
470
|
}
|
|
441
471
|
}
|
|
442
472
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
+
);
|
|
461
515
|
}
|
|
462
516
|
});
|
|
463
|
-
this.updateSelectedFilters(filter, "site", true);
|
|
464
517
|
}
|
|
465
518
|
}
|
|
466
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 = [
|
|
@@ -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();
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
description-markup='Your username must be in the form of an email address (it does not have to be real). It must be unique and cannot be associated with another Salesforce login credential. <a href="https://help.salesforce.com/s/articleView?id=sf.basics_intro_usernames_passwords.htm&type=5" target="_blank">Read more about username recommendations.</a>'
|
|
71
71
|
label="Username"
|
|
72
72
|
name="username"
|
|
73
|
-
placeholder="
|
|
73
|
+
placeholder="jane@company.sandbox"
|
|
74
74
|
required
|
|
75
75
|
type="email"
|
|
76
76
|
validity-on-blur={checkUsernameValidity}
|