@salesforcedevs/dw-components 1.14.7 → 1.15.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.14.7",
3
+ "version": "1.15.0",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -26,5 +26,5 @@
26
26
  "@types/setimmediate": "1.0.4",
27
27
  "setimmediate": "1.0.5"
28
28
  },
29
- "gitHead": "f3c08bcb4c3fa70aa7b29eeadaf1a718498f166a"
29
+ "gitHead": "f2ca29c18bf3158e8edc88a21402617e528f2243"
30
30
  }
@@ -3,3 +3,19 @@
3
3
  :host {
4
4
  display: contents;
5
5
  }
6
+
7
+ .featured-posts {
8
+ margin-bottom: var(--dx-g-spacing-xl);
9
+ }
10
+
11
+ @media screen and (min-width: 1025px) {
12
+ .hide-on-desktop {
13
+ display: none;
14
+ }
15
+ }
16
+
17
+ @media screen and (max-width: 1024px) {
18
+ .hide-on-small-screen {
19
+ display: none;
20
+ }
21
+ }
@@ -1,16 +1,78 @@
1
1
  <template>
2
- <template for:each={posts} for:item="post">
3
- <dx-card-blog-post
4
- label="BLOG POST"
5
- body={post.body}
6
- datetime={post.datetime}
7
- href={post.href}
8
- img-alt={post.imgAlt}
9
- img-src={post.imgSrc}
10
- key={post.id}
11
- header={post.title}
12
- authors={post.authors}
13
- ></dx-card-blog-post>
14
- <dx-hr spacing="2xs" class="mobile-divider_posts" key={post.id}></dx-hr>
2
+ <template lwc:if={hasBlogPosts}>
3
+ <div class="hide-on-small-screen">
4
+ <div class="featured-posts">
5
+ <dx-grid columns="two">
6
+ <dx-card-blog-post
7
+ label="BLOG POST"
8
+ body={firstPost.body}
9
+ datetime={firstPost.datetime}
10
+ href={firstPost.href}
11
+ img-alt={firstPost.imgAlt}
12
+ img-src={firstPost.imgSrc}
13
+ key={firstPost.id}
14
+ header={firstPost.title}
15
+ authors={firstPost.authors}
16
+ ></dx-card-blog-post>
17
+ <dx-grid columns="one">
18
+ <template for:each={secondAndThird} for:item="post">
19
+ <dx-card-blog-post
20
+ layout="horizontal"
21
+ datetime={post.datetime}
22
+ href={post.href}
23
+ img-alt={post.imgAlt}
24
+ img-src={post.imgSrc}
25
+ key={post.id}
26
+ header={post.title}
27
+ authors={post.authors}
28
+ ></dx-card-blog-post>
29
+ </template>
30
+ </dx-grid>
31
+ </dx-grid>
32
+ </div>
33
+ <dx-grid columns="four">
34
+ <template for:each={restOfBlogPosts} for:item="post">
35
+ <dx-card-blog-post
36
+ label="BLOG POST"
37
+ body={post.body}
38
+ datetime={post.datetime}
39
+ href={post.href}
40
+ img-alt={post.imgAlt}
41
+ img-src={post.imgSrc}
42
+ key={post.id}
43
+ header={post.title}
44
+ authors={post.authors}
45
+ ></dx-card-blog-post>
46
+ <dx-hr
47
+ spacing="2xs"
48
+ class="mobile-divider_posts"
49
+ key={post.id}
50
+ ></dx-hr>
51
+ </template>
52
+ </dx-grid>
53
+ </div>
54
+
55
+ <div class="hide-on-desktop">
56
+ <dx-grid columns="three">
57
+ <template for:each={sortedPosts} for:item="post">
58
+ <dx-card-blog-post
59
+ label="BLOG POST"
60
+ body={post.body}
61
+ datetime={post.datetime}
62
+ href={post.href}
63
+ img-alt={post.imgAlt}
64
+ img-src={post.imgSrc}
65
+ key={post.id}
66
+ header={post.title}
67
+ authors={post.authors}
68
+ ></dx-card-blog-post>
69
+ <dx-hr
70
+ spacing="2xs"
71
+ class="mobile-divider_posts"
72
+ key={post.id}
73
+ ></dx-hr>
74
+ </template>
75
+ </dx-grid>
76
+ </div>
15
77
  </template>
16
78
  </template>
@@ -1,6 +1,12 @@
1
1
  import { LightningElement, api, track } from "lwc";
2
- import { fetchWordpressPosts } from "dxUtils/wordpress";
3
- import { normalizePost } from "dxUtils/normalizers";
2
+ import {
3
+ fetchSingleWordpressPost,
4
+ fetchWordpressPosts
5
+ } from "dxUtils/wordpress";
6
+ import {
7
+ normalizePost,
8
+ normalizeSinglePostResponse
9
+ } from "dxUtils/normalizers";
4
10
 
5
11
  type BlogPost = {
6
12
  body: string;
@@ -11,9 +17,71 @@ type BlogPost = {
11
17
  };
12
18
 
13
19
  export default class CardBlogPostProvider extends LightningElement {
14
- @api count?: string;
20
+ @api count: string = "7";
21
+ @track _sortedPosts: BlogPost[] = [];
15
22
 
16
- @track posts: BlogPost[] = [];
23
+ private _featuredPost: BlogPost | undefined;
24
+ private _posts: BlogPost[] = [];
25
+
26
+ set posts(posts: BlogPost[]) {
27
+ this._posts = posts;
28
+ if (this._featuredPost) {
29
+ this._sortedPosts = [
30
+ this._featuredPost,
31
+ ...this.filterOutFeaturedPost(posts)
32
+ ];
33
+ } else {
34
+ this._sortedPosts = posts;
35
+ }
36
+ }
37
+
38
+ get sortedPosts() {
39
+ return this._sortedPosts;
40
+ }
41
+
42
+ set featuredPost(featuredPost: BlogPost) {
43
+ this._featuredPost = featuredPost;
44
+ this._sortedPosts = [
45
+ featuredPost,
46
+ ...this.filterOutFeaturedPost(this._posts)
47
+ ];
48
+ }
49
+
50
+ get hasBlogPosts() {
51
+ return this._sortedPosts && this._sortedPosts.length > 0;
52
+ }
53
+
54
+ // the three sections used in the desktop view
55
+ get firstPost() {
56
+ return this._sortedPosts[0];
57
+ }
58
+
59
+ get secondAndThird() {
60
+ return this._sortedPosts.slice(1, 3);
61
+ }
62
+
63
+ get restOfBlogPosts() {
64
+ return this._sortedPosts.slice(3);
65
+ }
66
+
67
+ private filterOutFeaturedPost(posts: BlogPost[]) {
68
+ // the featured post + the rest must equal count
69
+ const countMinusOne = parseInt(this.count, 10) - 1;
70
+ return posts
71
+ .filter((post) => post.id !== this._featuredPost.id)
72
+ .slice(0, countMinusOne);
73
+ }
74
+
75
+ private fetchFeaturedPost = async () => {
76
+ const FEATURED_BLOG_POST_ID = process.env.FEATURED_BLOG_POST_ID;
77
+ if (FEATURED_BLOG_POST_ID) {
78
+ this.featuredPost = await fetchSingleWordpressPost(
79
+ "/blogs/wp-json/wp/v2/posts",
80
+ FEATURED_BLOG_POST_ID,
81
+ normalizeSinglePostResponse
82
+ );
83
+ }
84
+ };
17
85
 
18
86
  private fetchPosts = async () => {
19
87
  this.posts = await fetchWordpressPosts(
@@ -24,6 +92,7 @@ export default class CardBlogPostProvider extends LightningElement {
24
92
  };
25
93
 
26
94
  connectedCallback() {
95
+ this.fetchFeaturedPost();
27
96
  this.fetchPosts();
28
97
  }
29
98
  }