| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import React from 'react';
- import PropTypes from 'prop-types';
- import Button from 'react-bootstrap/es/Button';
- import Tab from 'react-bootstrap/es/Tab';
- import Tabs from 'react-bootstrap/es/Tabs';
- import * as toastr from 'toastr';
- import UserPicture from '../User/UserPicture';
- import ReactUtils from '../ReactUtils';
- /**
- *
- * @author Yuki Takei <yuki@weseek.co.jp>
- *
- * @export
- * @class Comment
- * @extends {React.Component}
- */
- export default class CommentForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- };
- // this.updateState = this.updateState.bind(this);
- // this.updateStateCheckbox = this.updateStateCheckbox.bind(this);
- // this.postComment = this.postComment.bind(this);
- // this.renderHtml = this.renderHtml.bind(this);
- // this.handleSelect = this.handleSelect.bind(this);
- // this.apiErrorHandler = this.apiErrorHandler.bind(this);
- // this.onUpload = this.onUpload.bind(this);
- // this.onSlackEnabledFlagChange = this.onSlackEnabledFlagChange.bind(this);
- // this.onSlackChannelsChange = this.onSlackChannelsChange.bind(this);
- // this.showCommentFormBtnClickHandler = this.showCommentFormBtnClickHandler.bind(this);
- }
- componentWillMount() {
- this.init();
- }
- init() {
- if (!this.props.pageId) {
- return;
- }
- }
- /**
- * Load data of comments and rerender <PageComments />
- */
- postComment(event) {
- if (event != null) {
- event.preventDefault();
- }
- // this.props.data.crowi.apiPost('/comments.add', {
- // commentForm: {
- // comment: this.state.comment,
- // _csrf: this.props.data.crowi.csrfToken,
- // page_id: this.props.data.pageId,
- // revision_id: this.props.data.revisionId,
- // is_markdown: this.state.isMarkdown,
- // replyTo: this.props.replyTo,
- // },
- // slackNotificationForm: {
- // isSlackEnabled: this.state.isSlackEnabled,
- // slackChannels: this.state.slackChannels,
- // },
- // })
- // .then((res) => {
- // if (this.props.onPostComplete != null) {
- // this.props.onPostComplete(res.comment);
- // }
- // this.setState({
- // comment: '',
- // isMarkdown: true,
- // html: '',
- // key: 1,
- // errorMessage: undefined,
- // isSlackEnabled: false,
- // });
- // // reset value
- // this.editor.setValue('');
- // })
- // .catch((err) => {
- // const errorMessage = err.message || 'An unknown error occured when posting comment';
- // this.setState({ errorMessage });
- // });
- }
- onUpload(file) {
- const endpoint = '/attachments.add';
- // // create a FromData instance
- // const formData = new FormData();
- // formData.append('_csrf', this.props.data.crowi.csrfToken);
- // formData.append('file', file);
- // formData.append('path', this.props.data.pagePath);
- // formData.append('page_id', this.props.data.pageId || 0);
- // // post
- // this.props.data.crowi.apiPost(endpoint, formData)
- // .then((res) => {
- // const attachment = res.attachment;
- // const fileName = attachment.originalName;
- // let insertText = `[${fileName}](${attachment.filePathProxied})`;
- // // when image
- // if (attachment.fileFormat.startsWith('image/')) {
- // // modify to "" syntax
- // insertText = `!${insertText}`;
- // }
- // this.editor.insertText(insertText);
- // })
- // .catch(this.apiErrorHandler)
- // // finally
- // .then(() => {
- // this.editor.terminateUploadingState();
- // });
- }
- apiErrorHandler(error) {
- toastr.error(error.message, 'Error occured', {
- closeButton: true,
- progressBar: true,
- newestOnTop: false,
- showDuration: '100',
- hideDuration: '100',
- timeOut: '3000',
- });
- }
- render() {
- const children = React.Children.map(this.props.children, (child) => {
- return React.cloneElement(child, {
- onPostComplete: this.props.onPostComplete,
- replyTo: this.props.replyTo,
- pageId: this.props.pageId,
- pagePath: this.props.pagePath,
- slackChannels: this.props.slackChannels,
- revisionId: this.props.revisionId,
- });
- });
- return (
- <div>
- {children}
- </div>
- );
- }
- }
- CommentForm.propTypes = {
- children: PropTypes.node.isRequired,
- onPostComplete: PropTypes.func,
- replyTo: PropTypes.string,
- pageId: PropTypes.string,
- pagePath: PropTypes.string,
- slackChannels: PropTypes.string,
- revisionId: PropTypes.string,
- crowi: PropTypes.object.isRequired,
- };
|