From d69e9ef8975bd906e1a3ce89da3a702a7ae3c6b6 Mon Sep 17 00:00:00 2001 From: sina_sajjadi Date: Mon, 30 Sep 2024 12:18:01 +0330 Subject: [PATCH] blog bugs fixed --- src/app/blog/[...slug]/page.tsx | 51 ++++++++++++++++++++------------- src/shared/Badge.tsx | 4 +-- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/app/blog/[...slug]/page.tsx b/src/app/blog/[...slug]/page.tsx index 25aa5af..0dfa701 100644 --- a/src/app/blog/[...slug]/page.tsx +++ b/src/app/blog/[...slug]/page.tsx @@ -27,11 +27,19 @@ const Page = ({ }) => { const [blog, setBlog] = useState(); + const [posts, setPosts] = useState([]); + + useEffect(() => { + axiosInstance.get("/api/blogs/").then((response) => { + setPosts(response.data.results); + }); + }, []); + useEffect(() => { axiosInstance.get(`/api/blogs/${params.slug[0]}/`).then((response) => { setBlog(response.data); }); - }); + }, []); const renderHeader = () => { return (
@@ -96,22 +104,19 @@ const Page = ({ const renderTags = () => { console.log(blog?.tags[0].name); - return( - - (
- {blog?.tags.map((item) => ( - - + return ( +
+ {blog?.tags.map((item) => ( {item.name} - - ))} -
) -) + ))} +
+ ); }; const renderCommentForm = () => { @@ -155,6 +160,7 @@ const Page = ({ ); }; + console.log(posts); const renderPostRelated = (post: PostDataType) => { return ( @@ -162,10 +168,10 @@ const Page = ({ key={post.id} className="relative aspect-w-3 aspect-h-4 rounded-3xl overflow-hidden group" > - +
-

{post.title}

- + {/* {post.author.displayName} - · - {post.date} + · */} + + {post.created_at.split("T")[0]} +
- + ); }; @@ -211,8 +218,12 @@ const Page = ({

Related posts

- {/* */} - {DEMO_POSTS.filter((_, i) => i < 4).map(renderPostRelated)} + {console.log(params.slug[0], posts)} + {posts + .filter((_, i) => { + return _?.slug !== params.slug[0]; + }) + .map((item, i) => i < 4 && renderPostRelated(item))} {/* */}
diff --git a/src/shared/Badge.tsx b/src/shared/Badge.tsx index dee49a0..3b80b1b 100644 --- a/src/shared/Badge.tsx +++ b/src/shared/Badge.tsx @@ -38,7 +38,7 @@ const Badge: FC = ({ }`; } }; - const getStatus = (hasHover = true) => { + const getStatus = () => { switch (color) { case "SOLD_OUT": return `Sold Out`; @@ -51,7 +51,7 @@ const Badge: FC = ({ return `Booked`; default: - return `None`; + return color; } };