import React from 'react'; import PropTypes from 'prop-types'; /** * * @author Yuki Takei * * @export * @class Comment * @extends {React.Component} */ export default class CommentForm extends React.Component { constructor(props) { super(props); this.state = { comment: '', isMarkdown: false, }; this.handleChange = this.handleChange.bind(this); this.postComment = this.postComment.bind(this); this.reload = this.reload.bind(this); } handleChange(event) { const target = event.target; const value = target.type === 'checkbox' ? target.checked : target.value; const name = target.name; this.setState({ [name]: value }); } postComment(event) { event.preventDefault(); this.props.crowi.apiPost('/comments.add', { commentForm: { comment: this.state.comment, _csrf: this.props.crowi.csrfToken, page_id: this.props.pageId, revision_id: this.props.revisionId, is_markdown: this.state.isMarkdown, } }) .then(() => { this.reload(); }); } reload() { this.props.pageComments.init(); this.setState({ comment: '', isMarkdown: false, }); } render() { //{% if not user %}disabled{% endif %}をtextareaとbuttonに追加 // denounce/throttle return (
{{ user.name }}
Markdown
); } } CommentForm.propTypes = { pageComments: PropTypes.object.isRequired, crowi: PropTypes.object.isRequired, pageId: PropTypes.string, revisionId: PropTypes.string, };