Skip to content

Commit ef07a2b

Browse files
committed
display member join date in blog details page
1 parent 8093e6e commit ef07a2b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Pages/BlogPostDetails/BlogPostDetails.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,40 @@ import remarkMath from 'remark-math';
77
import rehypeKatex from 'rehype-katex';
88
import { remarkExtendedTable, extendedTableHandlers } from 'remark-extended-table';
99
import { FiClock } from 'react-icons/fi';
10+
import { useAuthState } from 'react-firebase-hooks/auth/dist/index.cjs';
11+
import auth from '../../Hooks/Firebase.Init';
12+
import Loading from '../../Components/Loading';
13+
import { toast } from 'react-toastify';
1014

1115
const BlogPostDetails = () => {
1216
const { _id } = useParams();
1317
const [postDetails, setPostDetails] = useState([]);
18+
const [userData, setUserData] = useState([]);
1419
const navigate = useNavigate();
20+
const [user, loading, error] = useAuthState(auth);
21+
const currentUserEmail = user?.email || user?.user?.email;
1522

1623
useEffect(() => {
1724
fetch(`https://a-coders-diary.herokuapp.com/post-details/${_id}`)
1825
.then(res => res.json())
1926
.then(data => setPostDetails(data));
2027
}, [postDetails, _id]);
2128

22-
const { postName, postDescription, postTags, postCategory, postAuthor, postAuthorImg, postDateTime } = postDetails;
29+
useEffect(() => {
30+
fetch(`https://a-coders-diary.herokuapp.com/users?userEmail=${currentUserEmail}`)
31+
.then(res => res.json())
32+
.then(data => setUserData(data));
33+
}, [currentUserEmail]);
34+
35+
if (loading) {
36+
return <Loading />;
37+
};
38+
39+
if (error) {
40+
toast.error(`${error?.message?.slice(17, -2)}`);
41+
};
42+
43+
const { postName, postDescription, postCategory, postAuthor, postAuthorImg, postDateTime } = postDetails;
2344

2445
return (
2546
<section className='mx-8'>
@@ -51,7 +72,7 @@ const BlogPostDetails = () => {
5172
<img className="w-10 h-10 rounded-full mr-4" src={postAuthorImg} alt="Avatar of Author" />
5273
<div className="flex-1 px-2">
5374
<p className="font-bold text-sm leading-none mb-2">{postAuthor?.split('@')[0]}</p>
54-
<p className="text-gray-600 text-xs md:text-base">Author Rank</p>
75+
<p className="text-gray-600 text-xs">Member since {userData?.[0]?.userCreationTime?.slice(0, 10)}</p>
5576
</div>
5677
<div className="justify-end">
5778
<button className="bg-transparent hover:bg-primary border border-primary text-xs text-primary hover:text-white font-bold py-2 px-4 rounded-full">About Author</button>

0 commit comments

Comments
 (0)