From 78286d3374b392183467fa14cebb8870ab447710 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 12 Apr 2017 20:51:18 -0300 Subject: [PATCH] Running CommentBox reducers and triggering actions from Plugins! --- client/coral-framework/reducers/index.js | 2 + client/coral-plugin-commentbox/CommentBox.js | 38 ++++++++----------- client/coral-plugin-commentbox/actions.js | 9 +++++ client/coral-plugin-commentbox/constants.js | 2 + client/coral-plugin-commentbox/index.js | 5 +++ client/coral-plugin-commentbox/reducer.js | 25 ++++++++++++ .../client/components/OffTopicCheckbox.js | 36 +++++++----------- 7 files changed, 71 insertions(+), 46 deletions(-) create mode 100644 client/coral-plugin-commentbox/actions.js create mode 100644 client/coral-plugin-commentbox/constants.js create mode 100644 client/coral-plugin-commentbox/index.js create mode 100644 client/coral-plugin-commentbox/reducer.js diff --git a/client/coral-framework/reducers/index.js b/client/coral-framework/reducers/index.js index fae7e60d5..d5b66bbae 100644 --- a/client/coral-framework/reducers/index.js +++ b/client/coral-framework/reducers/index.js @@ -1,11 +1,13 @@ import auth from './auth'; import user from './user'; import asset from './asset'; +import {reducer as commentBox} from '../../coral-plugin-commentbox'; import {pluginReducers} from '../helpers/plugins'; export default { auth, user, asset, + commentBox, ...pluginReducers }; diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index c506da0cc..37bb58f67 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -3,6 +3,8 @@ import {I18n} from '../coral-framework'; import translations from './translations.json'; import {Button} from 'coral-ui'; import {Slot} from 'coral-framework'; +import {connect} from 'react-redux'; +import {bindActionCreators} from 'redux'; const name = 'coral-plugin-commentbox'; @@ -13,10 +15,7 @@ class CommentBox extends Component { this.state = { username: '', - comment: { - body: '', - tags: [] - }, + body: '', hooks: { preSubmit: [], postSubmit: [] @@ -35,13 +34,14 @@ class CommentBox extends Component { countCache, addNotification, updateCountCache, - commentPostedHandler, + commentPostedHandler } = this.props; let comment = { asset_id: assetId, parent_id: parentId, - ...this.state.comment + body: this.state.body, + ...this.props.commentBox }; !isReply && updateCountCache(assetId, countCache + 1); @@ -70,12 +70,7 @@ class CommentBox extends Component { }) .catch((err) => console.error(err)); - this.setState({ - comment: { - ...this.state.comment, - body: '' - } - }); + this.setState({body: ''}); } registerHook = (hookType = '', hook = () => {}) => { @@ -126,20 +121,13 @@ class CommentBox extends Component { }); } - handleChange = e => { - this.setState({ - comment: { - ...this.state.comment, - body: e.target.value - } - }); - } + handleChange = e => this.setState({body: e.target.value}); render () { const {styles, isReply, authorId, charCount} = this.props; let {cancelButtonClicked} = this.props; - const length = this.state.comment.body.length; + const length = this.state.body.length; const enablePostComment = !length || (charCount && length > charCount); if (isReply && typeof cancelButtonClicked !== 'function') { @@ -159,7 +147,7 @@ class CommentBox extends Component {