diff --git a/app/blogs/[blogId]/page.tsx b/app/blogs/[blogId]/page.tsx index 226d148..2e753dd 100644 --- a/app/blogs/[blogId]/page.tsx +++ b/app/blogs/[blogId]/page.tsx @@ -1,16 +1,75 @@ "use client"; +import { FetchBlog, GetUserImage } from "@/actions/actions"; +import { blogs } from "@prisma/client"; +import Image from "next/image"; import { useParams } from "next/navigation"; -import React from "react"; +import { useEffect, useState } from "react"; -interface BlogIDProps { - searchParams: { [key: string]: string | string[] | undefined }; +interface CommentProp { + comment: string; + userName: string; } const Page = () => { + const { blogId } = useParams(); + const [blog, setBlog] = useState(); + const [image, setImage] = useState(""); + const [comments, setComments] = useState([]); + + const fetchImage = async () => { + const image = await GetUserImage(blog?.userId!); + setImage(image!); + }; + + const fetchBlog = async () => { + const blog = await FetchBlog(blogId); + const comment = blog?.comments as CommentProp[] | undefined; + setComments(comment); + setBlog(blog); + }; + + useEffect(() => { + fetchImage(); + }, [blog]); + + useEffect(() => { + fetchBlog(); + }); + return ( -
-

Blogs id

+
+
+
+
+ profile +
+ +
+

{blog?.username}

+

{blog?.title}

+
+
+
{blog?.content}
+
+
+ {comments?.map((cmt, index) => ( +
+

{cmt.userName}

+

{cmt.comment}

+
+ ))} +
+
+
); };