Skip to content

Commit

Permalink
Fix: If there's no posts show a message
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilalekha committed Jun 25, 2021
1 parent 988ccce commit a4225a1
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions component/layout/BlogPost/SectionRelated.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AuthorDetails from "../BlogListing/AuthorDetails";
import moment from "moment";

export default function SectionRelated({ title, posts }) {
// console.log({ posts });
// console.log(posts.length);
return (
<section className={`${styles.section} py-10 lg:py-20`}>
<div className="container">
Expand All @@ -19,33 +19,37 @@ export default function SectionRelated({ title, posts }) {
</span>
</div>
<div className={styles.relatedList}>
{posts.map((post) => (
<div className={styles.relatedItem} key={post._id}>
<figure>
<Link href={`/${post.slug}`}>
<a>
<img src={`${post.bannerImage}`} alt={`${post.title}`} />
</a>
</Link>
</figure>
<div className={styles.text}>
<p className={styles.date}>
{moment(post.publishedAt).format("MMMM Do, YYYY")}
</p>
<h3>
{posts.length > 0 ? (
posts.map((post) => (
<div className={styles.relatedItem} key={post._id}>
<figure>
<Link href={`/${post.slug}`}>
<a className="linkUnderline">
{/* 34 */}
{post.title.length > 34
? post.title.substring(0, 34) + "..."
: post.title}
<a>
<img src={`${post.bannerImage}`} alt={`${post.title}`} />
</a>
</Link>
</h3>
<AuthorDetails username={post.primaryAuthor.username} />
</figure>
<div className={styles.text}>
<p className={styles.date}>
{moment(post.publishedAt).format("MMMM Do, YYYY")}
</p>
<h3>
<Link href={`/${post.slug}`}>
<a className="linkUnderline">
{/* 34 */}
{post.title.length > 34
? post.title.substring(0, 34) + "..."
: post.title}
</a>
</Link>
</h3>
<AuthorDetails username={post.primaryAuthor.username} />
</div>
</div>
</div>
))}
))
) : (
<div>No blogs!</div>
)}
</div>
</div>
</section>
Expand Down

0 comments on commit a4225a1

Please sign in to comment.