Skip to content

Commit

Permalink
[feat]: add profile image in the blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddharthaMishra-dev committed Feb 16, 2024
1 parent 8b7657e commit af692e8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
13 changes: 13 additions & 0 deletions actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,16 @@ export async function DeleteBlog(props: string | string[]) {
console.log(err);
}
}

export async function GetUserImage(props: string) {
try {
const usr = await prisma.users.findFirst({
where: {
id: props,
},
});
return usr?.image || "";
} catch (err) {
console.log(err);
}
}
1 change: 0 additions & 1 deletion app/blogs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// "use client";
import { FetchAll } from "@/actions/actions";
import BlogList from "@/components/BlogList";

Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const roboto = Roboto({
});

export const metadata: Metadata = {
title: "blog-g-gers",
title: "blog-g-ers",
description: "Be yourself",
};

Expand Down
8 changes: 6 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import Link from "next/link";
export default function Home() {
return (
<main className="h-full flex flex-col items-center justify-center md:p-24 px-10">
<h1 className={` font-black mb-2 custom-text`}>Blog-g-ers</h1>
<h2 className="mt-2 text-2xl md:text-4xl text-gray-200"> Share who you are</h2>
<h1
className={`font-black mb-2 text-blue-600 text-[2rem] md:text-[4rem] lg:text-[6rem] xl:text-[10rem]`}
>
blog-g-ers
</h1>
<h2 className="mt-2 text-2xl md:text-4xl text-gray-200">Share who you are</h2>
<Link href="/blogs">
<Button
color="primary"
Expand Down
24 changes: 22 additions & 2 deletions components/BlogCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Card, CardBody, CardFooter, CardHeader } from "@nextui-org/card";
import type { blogs } from "@prisma/client";
import CommentButton from "./CommentButton";
import LikeButton from "./LikeButton";
import { useEffect, useState } from "react";
import { GetUserImage } from "@/actions/actions";

interface CardProps {
blog: blogs;
Expand All @@ -11,9 +13,20 @@ interface CardProps {
}

const BlogCard = ({ blog, handleLike, handleComment }: CardProps) => {
const [image, setImage] = useState("");

const fetchImage = async () => {
const image = await GetUserImage(blog.userId);
setImage(image!);
};

useEffect(() => {
fetchImage();
}, [blog]);

return (
<>
<Card className="w-full p-2 m-4 bg-theme text-cyan-50 font-semibold drop-shadow-2xl ">
<Card className="w-full p-2 m-4 bg-theme text-cyan-50 font-semibold drop-shadow-2xl bg-transparent">
<CardHeader className="text-2xl p-4">{blog.title}</CardHeader>
<CardBody className="p-4">{blog.content}</CardBody>
<CardFooter className="p-4 flex justify-between items-center">
Expand All @@ -27,7 +40,14 @@ const BlogCard = ({ blog, handleLike, handleComment }: CardProps) => {
handleComment={handleComment}
/>
</div>
<div className="p-4 bg-slate-900 rounded-lg">{blog.username}</div>
<div className="p-4 flex gap-x-2 items-center bg-slate-900 rounded-lg">
<img
className="h-6 w-6 rounded-full"
src={image}
alt="profile"
/>
{blog.username}
</div>
</CardFooter>
</Card>
</>
Expand Down
1 change: 1 addition & 0 deletions components/BlogList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const BlogList = ({ blogs }: BlogListProps) => {
handleLike={handleLike}
handleComment={handleComment}
/>
<div className="border-b" />
</li>
))}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Appbar = () => {
>
<NavbarBrand>
<Link href="/">
<p className="text-xl font-bold text-inherit">blog-g-gers</p>
<p className="text-xl font-bold text-inherit">blog-g-ers</p>
</Link>
</NavbarBrand>
<NavbarContent
Expand Down Expand Up @@ -119,7 +119,7 @@ const Appbar = () => {
className="font-semibold text-lg"
href="/signin"
>
Sign In
Sign in
</Button>
</NavbarItem>
)}
Expand Down

0 comments on commit af692e8

Please sign in to comment.