CommentEditorLazyRenderer.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import CommentEditor from './CommentEditor';
  4. import UserPicture from '../User/UserPicture';
  5. export default class CommentEditorLazyRenderer extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. isEditorShown: false,
  10. isLayoutTypeGrowi: false,
  11. };
  12. this.showCommentFormBtnClickHandler = this.showCommentFormBtnClickHandler.bind(this);
  13. }
  14. componentWillMount() {
  15. this.init();
  16. }
  17. init() {
  18. const layoutType = this.props.crowi.getConfig().layoutType;
  19. this.setState({ isLayoutTypeGrowi: layoutType === 'crowi-plus' || layoutType === 'growi' });
  20. }
  21. showCommentFormBtnClickHandler() {
  22. this.setState({ isEditorShown: true });
  23. }
  24. render() {
  25. const crowi = this.props.crowi;
  26. const username = crowi.me;
  27. const user = crowi.findUser(username);
  28. const isLayoutTypeGrowi = this.state.isLayoutTypeGrowi;
  29. return (
  30. <React.Fragment>
  31. { !this.state.isEditorShown
  32. && (
  33. <div className="form page-comment-form">
  34. { username
  35. && (
  36. <div className="comment-form">
  37. { isLayoutTypeGrowi
  38. && (
  39. <div className="comment-form-user">
  40. <UserPicture user={user} />
  41. </div>
  42. )
  43. }
  44. <div className="comment-form-main">
  45. <button
  46. type="button"
  47. className={`btn btn-lg ${this.state.isLayoutTypeGrowi ? 'btn-link' : 'btn-primary'} center-block`}
  48. onClick={this.showCommentFormBtnClickHandler}
  49. >
  50. <i className="icon-bubble"></i> Add Comment
  51. </button>
  52. </div>
  53. </div>
  54. )
  55. }
  56. </div>
  57. )
  58. }
  59. { this.state.isEditorShown
  60. && (
  61. <CommentEditor
  62. {...this.props}
  63. replyTo={undefined}
  64. >
  65. </CommentEditor>
  66. )
  67. }
  68. </React.Fragment>
  69. );
  70. }
  71. }
  72. CommentEditorLazyRenderer.propTypes = {
  73. crowi: PropTypes.object.isRequired,
  74. crowiOriginRenderer: PropTypes.object.isRequired,
  75. editorOptions: PropTypes.object,
  76. slackChannels: PropTypes.string,
  77. };