From b2428371c7799b7357578eebf826357537c2c5bb Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Mon, 24 Apr 2017 13:09:41 -0600 Subject: [PATCH] enable character counting on replies --- client/coral-embed-stream/src/Comment.js | 8 ++++++++ client/coral-embed-stream/src/Embed.js | 5 ++++- client/coral-embed-stream/src/Stream.js | 7 +++++++ client/coral-plugin-commentbox/CommentBox.js | 10 ++++++---- client/coral-plugin-replies/ReplyBox.js | 17 ++++++++++++++++- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index 674c03ec5..63b3ef8dc 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -64,6 +64,8 @@ class Comment extends React.Component { currentUser: PropTypes.shape({ id: PropTypes.string.isRequired }), + charCountEnable: PropTypes.bool.isRequired, + maxCharCount: PropTypes.number, comment: PropTypes.shape({ depth: PropTypes.number, action_summaries: PropTypes.array.isRequired, @@ -121,6 +123,8 @@ class Comment extends React.Component { ignoreUser, disableReply, commentIsIgnored, + maxCharCount, + charCountEnable, } = this.props; const likeSummary = getActionSummary('LikeActionSummary', comment); @@ -243,6 +247,8 @@ class Comment extends React.Component { commentPostedHandler={() => { setActiveReplyBox(''); }} + charCountEnable={charCountEnable} + maxCharCount={maxCharCount} setActiveReplyBox={setActiveReplyBox} parentId={parentId || comment.id} addNotification={addNotification} @@ -273,6 +279,8 @@ class Comment extends React.Component { addCommentTag={addCommentTag} removeCommentTag={removeCommentTag} ignoreUser={ignoreUser} + charCountEnable={charCountEnable} + maxCharCount={maxCharCount} showSignInDialog={showSignInDialog} reactKey={reply.id} key={reply.id} diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 51079097f..fbe24c8c7 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -214,7 +214,8 @@ class Embed extends React.Component { isReply={false} currentUser={this.props.auth.user} authorId={user.id} - charCount={asset.settings.charCountEnable && asset.settings.charCount} /> + charCountEnable={asset.settings.charCountEnable} + maxCharCount={asset.settings.charCount} /> : null } @@ -278,6 +279,8 @@ class Embed extends React.Component { deleteAction={this.props.deleteAction} showSignInDialog={this.props.showSignInDialog} comments={asset.comments} + maxCharCount={asset.settings.charCount} + charCountEnable={asset.settings.charCountEnable} ignoredUsers={this.props.userData.ignoredUsers} /> ignoredUsers && ignoredUsers.includes(comment.user.id); return ( @@ -84,6 +89,8 @@ class Stream extends React.Component { key={comment.id} reactKey={comment.id} comment={comment} + maxCharCount={maxCharCount} + charCountEnable={charCountEnable} pluginProps={pluginProps} /> ) diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index 2a988711d..261c95414 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -121,11 +121,11 @@ class CommentBox extends Component { handleChange = e => this.setState({body: e.target.value}); render () { - const {styles, isReply, authorId, charCount} = this.props; + const {styles, isReply, authorId, maxCharCount} = this.props; let {cancelButtonClicked} = this.props; const length = this.state.body.length; - const enablePostComment = !length || (charCount && length > charCount); + const enablePostComment = !length || (maxCharCount && length > maxCharCount); if (isReply && typeof cancelButtonClicked !== 'function') { console.warn('the CommentBox component should have a cancelButtonClicked callback defined if it lives in a Reply'); @@ -150,8 +150,8 @@ class CommentBox extends Component { onChange={this.handleChange} rows={3}/> -
charCount ? `${name}-char-max` : ''}`}> - {charCount && `${charCount - length} ${lang.t('characters-remaining')}`} +
maxCharCount ? `${name}-char-max` : ''}`}> + {maxCharCount && `${maxCharCount - length} ${lang.t('characters-remaining')}`}