@@ -6,6 +6,14 @@ import CommentForm from './CommentForm'
66import Context from '../modules/Context'
77import userStory from '../services/user_story'
88
9+ const attachFiles = ( formData , attachments ) => {
10+ if ( attachments . length ) {
11+ attachments . forEach ( ( file ) => {
12+ formData . append ( 'files.attachment' , file )
13+ } )
14+ }
15+ }
16+
917const toggleReplyForm = ( repliesToggled , setRepliesToggled , key ) => {
1018 repliesToggled === key + 1
1119 ? setRepliesToggled ( null )
@@ -58,15 +66,9 @@ const Comments = (props) => {
5866 useEffect (
5967 ( ) => ( ) => {
6068 attachments . forEach ( ( file ) => URL . revokeObjectURL ( file . preview ) )
61- } ,
62- [ attachments ]
63- )
64-
65- useEffect (
66- ( ) => ( ) => {
6769 replyAttachments . forEach ( ( file ) => URL . revokeObjectURL ( file . preview ) )
6870 } ,
69- [ replyAttachments ]
71+ [ attachments , replyAttachments ]
7072 )
7173
7274 const addComment = async ( data ) => {
@@ -75,11 +77,7 @@ const Comments = (props) => {
7577 data . user_story = storyId
7678 formData . append ( 'data' , JSON . stringify ( data ) )
7779
78- if ( attachments . length ) {
79- attachments . forEach ( ( file ) => {
80- formData . append ( 'files.attachment' , file )
81- } )
82- }
80+ attachFiles ( formData , attachments )
8381
8482 await userStory . postComment ( formData )
8583 setComment ( '' )
@@ -94,11 +92,7 @@ const Comments = (props) => {
9492 data . user_story_comment = commentId
9593 formData . append ( 'data' , JSON . stringify ( data ) )
9694
97- if ( replyAttachments . length ) {
98- replyAttachments . forEach ( ( file ) => {
99- formData . append ( 'files.attachment' , file )
100- } )
101- }
95+ attachFiles ( formData , replyAttachments )
10296
10397 await userStory . postCommentReply ( formData )
10498 setCommentReply ( '' )
0 commit comments