1- import { useState } from "react" ;
1+ import { useEffect , useState } from "react" ;
22import Image from "next/image" ;
33import Link from "next/link" ;
44import FeedPostModal from "@/components/modals/FeedPostModal" ;
55import { Box } from "@/components/shared/dashboard" ;
66import { defaultAvatar } from "@/public/assets/images" ;
7+ import { useUserStore } from "@/store/codev-store" ;
78import { format } from "date-fns" ;
89import { ArrowBigUp } from "lucide-react" ;
910import toast from "react-hot-toast" ;
@@ -14,12 +15,29 @@ import PostUpvote from "./PostUpvote";
1415
1516interface PostProps {
1617 post : PostType ;
17- isMentor ?: boolean ;
18+ isAdmin ?: boolean ;
1819 onDelete ?: ( deletedPostId : string | number ) => void ;
1920}
2021
21- export default function Post ( { post, isMentor , onDelete } : PostProps ) {
22+ export default function Post ( { post, isAdmin , onDelete } : PostProps ) {
2223 const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
24+ const [ isAuthor , setIsAuthor ] = useState ( false ) ;
25+ const { user } = useUserStore ( ) ;
26+
27+ useEffect ( ( ) => {
28+ const checkIfAuthor = async ( ) => {
29+ if ( ! user ) return ;
30+ if ( user . id === post . author_id ?. id ) {
31+ setIsAuthor ( true ) ;
32+ } else {
33+ setIsAuthor ( false ) ;
34+ }
35+ } ;
36+
37+ if ( user ) {
38+ checkIfAuthor ( ) ;
39+ }
40+ } , [ user ] ) ;
2341
2442 const handleDelete = async ( e : React . MouseEvent ) => {
2543 e . stopPropagation ( ) ;
@@ -37,12 +55,6 @@ export default function Post({ post, isMentor, onDelete }: PostProps) {
3755 }
3856 } ;
3957
40- const handleUpvote = ( e : React . MouseEvent ) => {
41- e . stopPropagation ( ) ;
42- e . preventDefault ( ) ;
43- // You can add upvote logic here
44- } ;
45-
4658 const openModal = ( ) => setIsModalOpen ( true ) ;
4759 const closeModal = ( ) => setIsModalOpen ( false ) ;
4860 return (
@@ -52,7 +64,7 @@ export default function Post({ post, isMentor, onDelete }: PostProps) {
5264 onClick = { openModal }
5365 >
5466 { /* Delete Button in top-right */ }
55- { isMentor && (
67+ { ( isAdmin || isAuthor ) && (
5668 < button
5769 className = "invisible absolute right-2 top-2 rounded bg-red-500 px-2 py-1 text-white hover:bg-red-600 group-hover:visible"
5870 onClick = { handleDelete }
0 commit comments