File size: 1,117 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { some } from 'lodash';
import PropTypes from 'prop-types';
import PostCommentForm from './form';

const noop = () => {};

/*
 * A component for displaying a comment form at the root of a conversation.
 */
const PostCommentFormRoot = ( {
	post,
	commentText,
	activeReplyCommentId,
	commentsTree,
	onUpdateCommentText = noop,
	isInlineComment,
} ) => {
	// Are we displaying the comment form elsewhere? If so, don't render the root form.
	if (
		activeReplyCommentId ||
		some( commentsTree, ( comment ) => {
			return comment.data && comment.data.isPlaceholder && ! comment.data.parent;
		} )
	) {
		return null;
	}

	return (
		<PostCommentForm
			post={ post }
			parentCommentId={ null }
			commentText={ commentText }
			onUpdateCommentText={ onUpdateCommentText }
			isInlineComment={ isInlineComment }
		/>
	);
};

PostCommentFormRoot.propTypes = {
	post: PropTypes.object.isRequired,
	commentText: PropTypes.string,
	activeReplyCommentId: PropTypes.number,
	commentsTree: PropTypes.object,
	onUpdateCommentText: PropTypes.func,
	isInlineComment: PropTypes.bool,
};

export default PostCommentFormRoot;