-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostReplyForm.jsx
63 lines (55 loc) · 1.66 KB
/
postReplyForm.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
import { useState } from 'react';
import { db } from '../firebase/config';
import { postReply } from '../hooks/postReply';
import { getReplies } from '../hooks/getReplies';
import { useAuthContext } from '../hooks/useAuthContext';
import styles from '../css/postReplies.module.css';
import { motion } from 'framer-motion';
const buttonVariants = {
hover: {
scale: 1.06,
},
tap: {
scale: 0.99,
},
};
export default function PostReplyForm({ postId, setReplies }) {
const [postReplyInput, setPostReplyInput] = useState('');
const { user } = useAuthContext();
function handleSubmit(e) {
e.preventDefault();
postReply(postReplyInput, postId, user.displayName, user.photoURL);
setTimeout(() => {
getReplies(postId).then((response) => {
setPostReplyInput('');
setReplies(response);
});
}, 150);
}
function onChangePostReply(e) {
setPostReplyInput(e.target.value);
}
return (
<div className="flex flex-col pb-12 w-full ">
<form onSubmit={handleSubmit} className={styles.form}>
<textarea
className="p-5 resize-none drop-shadow-md my-5 rounded-lg bg-[#ffffff] border-2 border-[#eaeaea]"
onChange={onChangePostReply}
value={postReplyInput}
placeholder="Reply to this post"
spellCheck="true"
maxLength={300}
required
/>
<motion.button
variants={buttonVariants}
whileHover="hover"
whileTap="tap"
className="w-1/2 md:w-1/4 m-auto h-12 text-white rounded-lg bg-[#4f9cf9] cursor-pointer border-none"
>
Reply
</motion.button>
</form>
</div>
);
}