Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog id page #11

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions app/blogs/[blogId]/page.tsx
Original file line number Diff line number Diff line change
@@ -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<blogs | undefined | null>();
const [image, setImage] = useState("");
const [comments, setComments] = useState<CommentProp[] | undefined>([]);

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 (
<div>
<h1>Blogs id</h1>
<div className="h-full w-full overflow-auto p-4 flex flex-col items-center">
<div className="h-full w-full max-w-lg ">
<div className="mt-2 flex justify-start items-center space-x-2">
<div className="relative h-16 w-16">
<Image
fill
className="rounded-full object-center object-cover"
src={image}
alt="profile"
/>
</div>

<div className="flex flex-col space-y-1">
<p className="text-2xl font-semibold">{blog?.username}</p>
<p className="text-xl font-medium">{blog?.title}</p>
</div>
</div>
<div className="w-full mt-4 px-3 py-7 rounded-md">{blog?.content}</div>
<div className="w-full mt-4 border-t ">
<div className="flex flex-col justify-center">
{comments?.map((cmt, index) => (
<div
key={index}
className="px-2 py-5 border-b border-gray-600"
>
<p className="mb-5 text-sm font-medium tracking-wider">{cmt.userName}</p>
<p>{cmt.comment}</p>
</div>
))}
</div>
</div>
</div>
</div>
);
};
Expand Down
Loading