@salesforcedevs/dw-components 1.14.7 → 1.15.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.
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.2",
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": "b8602f13fe7f2d709dd2843eb07121fc05844906"
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,61 @@
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
19
+ for:each={secondThirdAndFourth}
20
+ for:item="post"
21
+ >
22
+ <dx-card-blog-post
23
+ layout="horizontal"
24
+ datetime={post.datetime}
25
+ href={post.href}
26
+ img-alt={post.imgAlt}
27
+ img-src={post.imgSrc}
28
+ key={post.id}
29
+ header={post.title}
30
+ authors={post.authors}
31
+ ></dx-card-blog-post>
32
+ </template>
33
+ </dx-grid>
34
+ </dx-grid>
35
+ </div>
36
+ </div>
37
+
38
+ <div class="hide-on-desktop">
39
+ <dx-grid columns="three">
40
+ <template for:each={sortedPosts} for:item="post">
41
+ <dx-card-blog-post
42
+ label="BLOG POST"
43
+ body={post.body}
44
+ datetime={post.datetime}
45
+ href={post.href}
46
+ img-alt={post.imgAlt}
47
+ img-src={post.imgSrc}
48
+ key={post.id}
49
+ header={post.title}
50
+ authors={post.authors}
51
+ ></dx-card-blog-post>
52
+ <dx-hr
53
+ spacing="2xs"
54
+ class="mobile-divider_posts"
55
+ key={post.id}
56
+ ></dx-hr>
57
+ </template>
58
+ </dx-grid>
59
+ </div>
15
60
  </template>
16
61
  </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,67 @@ type BlogPost = {
11
17
  };
12
18
 
13
19
  export default class CardBlogPostProvider extends LightningElement {
14
- @api count?: string;
20
+ @api count: string = "4";
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, this._featuredPost)
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, featuredPost)
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 secondThirdAndFourth() {
60
+ return this._sortedPosts.slice(1, 4);
61
+ }
62
+
63
+ private filterOutFeaturedPost(posts: BlogPost[], featuredPost: BlogPost) {
64
+ // the featured post + the rest must equal count
65
+ const countMinusOne = parseInt(this.count, 10) - 1;
66
+ return posts
67
+ .filter((post) => post.id !== featuredPost.id)
68
+ .slice(0, countMinusOne);
69
+ }
70
+
71
+ private fetchFeaturedPost = async () => {
72
+ const FEATURED_BLOG_POST_ID = process.env.FEATURED_BLOG_POST_ID;
73
+ if (FEATURED_BLOG_POST_ID) {
74
+ this.featuredPost = await fetchSingleWordpressPost(
75
+ "/blogs/wp-json/wp/v2/posts",
76
+ FEATURED_BLOG_POST_ID,
77
+ normalizeSinglePostResponse
78
+ );
79
+ }
80
+ };
17
81
 
18
82
  private fetchPosts = async () => {
19
83
  this.posts = await fetchWordpressPosts(
@@ -24,6 +88,7 @@ export default class CardBlogPostProvider extends LightningElement {
24
88
  };
25
89
 
26
90
  connectedCallback() {
91
+ this.fetchFeaturedPost();
27
92
  this.fetchPosts();
28
93
  }
29
94
  }