forked from adrianhajdin/project_next_14_ai_prompt_sharing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromptCard.jsx
96 lines (83 loc) · 2.7 KB
/
PromptCard.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use client";
import { useState } from "react";
import Image from "next/image";
import { useSession } from "next-auth/react";
import { usePathname, useRouter } from "next/navigation";
const PromptCard = ({ post, handleEdit, handleDelete, handleTagClick }) => {
const { data: session } = useSession();
const pathName = usePathname();
const router = useRouter();
const [copied, setCopied] = useState("");
const handleProfileClick = () => {
console.log(post);
if (post.creator._id === session?.user.id) return router.push("/profile");
router.push(`/profile/${post.creator._id}?name=${post.creator.username}`);
};
const handleCopy = () => {
setCopied(post.prompt);
navigator.clipboard.writeText(post.prompt);
setTimeout(() => setCopied(false), 3000);
};
return (
<div className='prompt_card'>
<div className='flex justify-between items-start gap-5'>
<div
className='flex-1 flex justify-start items-center gap-3 cursor-pointer'
onClick={handleProfileClick}
>
<Image
src={post.creator.image}
alt='user_image'
width={40}
height={40}
className='rounded-full object-contain'
/>
<div className='flex flex-col'>
<h3 className='font-satoshi font-semibold text-gray-900'>
{post.creator.username}
</h3>
<p className='font-inter text-sm text-gray-500'>
{post.creator.email}
</p>
</div>
</div>
<div className='copy_btn' onClick={handleCopy}>
<Image
src={
copied === post.prompt
? "/assets/icons/tick.svg"
: "/assets/icons/copy.svg"
}
alt={copied === post.prompt ? "tick_icon" : "copy_icon"}
width={12}
height={12}
/>
</div>
</div>
<p className='my-4 font-satoshi text-sm text-gray-700'>{post.prompt}</p>
<p
className='font-inter text-sm blue_gradient cursor-pointer'
onClick={() => handleTagClick && handleTagClick(post.tag)}
>
#{post.tag}
</p>
{session?.user.id === post.creator._id && pathName === "/profile" && (
<div className='mt-5 flex-center gap-4 border-t border-gray-100 pt-3'>
<p
className='font-inter text-sm green_gradient cursor-pointer'
onClick={handleEdit}
>
Edit
</p>
<p
className='font-inter text-sm orange_gradient cursor-pointer'
onClick={handleDelete}
>
Delete
</p>
</div>
)}
</div>
);
};
export default PromptCard;