Vulcan/packages/nova-components/lib/comments/list/CommentNew.jsx

53 lines
1.4 KiB
React
Raw Normal View History

2016-02-18 17:53:04 +09:00
import Formsy from 'formsy-react';
import FRC from 'formsy-react-components';
const Textarea = FRC.Textarea;
const CommentNew = React.createClass({
propTypes: {
postId: React.PropTypes.string.isRequired,
2016-02-18 21:39:33 +09:00
submitCallback: React.PropTypes.func, // a callback to execute when the submission has been successful
type: React.PropTypes.string, // "comment" or "reply"
comment: React.PropTypes.object, // if reply, the comment being replied to
parentCommentId: React.PropTypes.string, // if reply
topLevelCommentId: React.PropTypes.string // if reply
2016-02-18 17:53:04 +09:00
},
submitComment(data) {
data = {
...data,
2016-02-18 21:39:33 +09:00
postId: this.props.comment.postId,
parentCommentId: this.props.comment._id
2016-02-18 17:53:04 +09:00
}
2016-02-18 21:39:33 +09:00
// if comment being replied to has a parent use its topLevelCommentId; if it doesn't then it *is* the top level comment
data.topLevelCommentId = this.props.comment.parentCommentId ? this.props.comment.topLevelCommentId : this.props.comment._id;
2016-02-18 17:53:04 +09:00
Meteor.call("comments.new", data, (error, result) => {
2016-02-18 21:39:33 +09:00
if (error) {
// handle error
} else {
2016-02-18 17:53:04 +09:00
this.props.submitCallback();
}
});
},
render() {
return (
<Formsy.Form onSubmit={this.submitComment}>
<Textarea
name="body"
value=""
label="Body"
type="text"
/>
<button type="submit">Submit</button>
</Formsy.Form>
)
}
});
module.exports = CommentNew;