-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostReplies.jsx
71 lines (66 loc) · 2.31 KB
/
PostReplies.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
import React from 'react';
import styles from '../css/postReplies.module.css';
import moment from 'moment';
import { useAuthContext } from '../hooks/useAuthContext';
import { useRouter } from 'next/router';
import { motion } from 'framer-motion';
const buttonVariants = {
hover: {
scale: 1.06,
},
tap: {
scale: 0.99,
},
};
export default function PostReplies({ postId, replies, handleDeleteReply }) {
const { user } = useAuthContext();
const router = useRouter();
return (
<div>
{replies?.length ? (
replies.map((reply) => (
<div key={reply.replyId} className="flex flex-col w-full pb-12">
<div className="flex items-start gap-4 border border-[#eaeaea] p-5">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={reply.avatarURL}
alt="profile"
className="rounded-full h-16 w-16 cursor-pointer"
onClick={() => router.push(`/users/${user?.displayName}`)}
/>
<div className="flex-1">
<div className="flex items-center">
<span
className="text-blue-500 cursor-pointer hover:underline"
onClick={() => router.push(`/users/${reply.user}`)}
>
{reply.user}
</span>
<span className="text-gray-500 ml-2">
{moment(reply.createdAt).fromNow()}
</span>
</div>
<div className="mt-2">
<div className={styles.reply}>{reply.message}</div>
{reply?.user === user?.displayName && (
<motion.button
variants={buttonVariants}
whileHover="hover"
whileTap="tap"
className="text-white w-30 border-none rounded-lg mt-5 cursor-pointer p-1.5 bg-[#4f9cf9]"
onClick={() => handleDeleteReply(reply.replyId)}
>
Delete
</motion.button>
)}
</div>
</div>
</div>
</div>
))
) : (
<div className="text-gray-500">No replies yet...</div>
)}
</div>
);
}