Skip to content

Commit 903276d

Browse files
committed
imporved UI to communicate to the user who is the author of which blogpost
1 parent 96c8499 commit 903276d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/components/BlogpostDetails.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ import Loader from "./Loader";
1414
export interface Blogpost {
1515
_id: string;
1616
title: string;
17-
author: string;
17+
author: { _id: string; email: string };
1818
blogpost: string;
1919
createdAt: string;
2020
}
2121

2222
interface BlogPostProps {
2323
title: string;
24-
author: string;
24+
author: { _id: string; email: string };
2525
createdAt: string;
2626
blogpost: Blogpost;
2727
setShowModal: (value: boolean) => void;
2828
}
2929

3030
const BlogDetails = ({ blogpost }: BlogPostProps ) => {
31+
const { title, author, createdAt } = blogpost;
3132
const { user } = useAuthContext();
3233
const { dispatch } = useBlogpostsContext();
3334
const headers = useMemo(() => {
@@ -90,13 +91,13 @@ const BlogDetails = ({ blogpost }: BlogPostProps ) => {
9091
{blog && (
9192
<article>
9293
<Typography variant="h3" align="left">
93-
{blogpost.title}
94+
{title}
9495
</Typography>
9596
<Typography variant="subtitle1">
96-
<strong>Written by {blogpost.author}</strong>
97+
<strong>Written by {author.email}</strong>
9798
</Typography>
9899
<Typography variant="subtitle2">
99-
{formatDistanceToNow(new Date(blogpost.createdAt), {
100+
{formatDistanceToNow(new Date(createdAt), {
100101
addSuffix: true,
101102
})}
102103
</Typography>

src/pages/Home.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ const Home = ({ setShowModal }: HomeProps) => {
4444
{error && <div>{error}</div>}
4545
{isPending && <Shimmer />}
4646
{blogposts &&
47-
blogposts.map((blogpost: Blogpost) => {
47+
blogposts
48+
.slice(0, 3)
49+
.map((blogpost: Blogpost) => {
4850
const { title, author, createdAt, _id } = blogpost;
51+
console.log(blogpost.author);
4952
return (
5053
<BlogDetails
5154
key={_id}

0 commit comments

Comments
 (0)