@@ -2,9 +2,10 @@ import React from 'react'
22import { useForm } from 'react-hook-form'
33
44import Button from './Button'
5- import FormError from '../components/FormError'
5+ import FormError from './FormError'
6+ import MediaPreview from './MediaPreview'
67
7- const CommentInput = ( props ) => {
8+ const CommentForm = ( props ) => {
89 const {
910 attachments,
1011 setAttachments,
@@ -20,24 +21,6 @@ const CommentInput = (props) => {
2021
2122 const { register : registerComment , errors : errorsComment } = useForm ( )
2223
23- const removeFile = ( name ) => {
24- setAttachments ( attachments . filter ( ( attachment ) => attachment . name !== name ) )
25- }
26-
27- const mediaPreview = attachments . map ( ( file ) => (
28- < div className = 'preview-root' key = { file . name } >
29- < button
30- className = 'preview-remove-button'
31- onClick = { ( ) => removeFile ( file . name ) }
32- >
33- x
34- </ button >
35- < div className = 'preview-inner' >
36- < img src = { file . preview } className = 'preview-image' alt = 'preview' />
37- </ div >
38- </ div >
39- ) )
40-
4124 const handleFileChange = async ( event ) => {
4225 const newFiles = event . target . files
4326 const newFilesArray = [ ]
@@ -60,7 +43,7 @@ const CommentInput = (props) => {
6043 < textarea
6144 rows = '5'
6245 cols = '25'
63- name = 'Comments '
46+ name = 'addReply '
6447 ref = { registerReply ( { required : true } ) }
6548 value = { commentReply }
6649 onChange = { ( e ) => setCommentReply ( e . target . value ) }
@@ -81,7 +64,10 @@ const CommentInput = (props) => {
8164 { errorsReply . Comments && (
8265 < FormError message = 'Reply cannot be empty' />
8366 ) }
84- < div className = 'preview-container' > { mediaPreview } </ div >
67+ < MediaPreview
68+ attachments = { attachments }
69+ setAttachments = { setAttachments }
70+ />
8571 </ div >
8672 ) : (
8773 ''
@@ -114,7 +100,10 @@ const CommentInput = (props) => {
114100 { errorsComment . addComment && (
115101 < FormError message = 'Comment cannot be empty' />
116102 ) }
117- < div className = 'preview-container' > { mediaPreview } </ div >
103+ < MediaPreview
104+ attachments = { attachments }
105+ setAttachments = { setAttachments }
106+ />
118107 </ div >
119108 ) : (
120109 ''
@@ -123,4 +112,4 @@ const CommentInput = (props) => {
123112 )
124113}
125114
126- export default CommentInput
115+ export default CommentForm
0 commit comments