import React from 'react'; import PropTypes from 'prop-types'; import { createSubscribedElement } from '../UnstatedUtils'; import AppContainer from '../../services/AppContainer'; import UserPicture from '../User/UserPicture'; import CommentEditor from './CommentEditor'; class CommentEditorLazyRenderer extends React.Component { constructor(props) { super(props); this.state = { isEditorShown: false, }; this.growiRenderer = this.props.appContainer.getRenderer('comment'); this.showCommentFormBtnClickHandler = this.showCommentFormBtnClickHandler.bind(this); } showCommentFormBtnClickHandler() { this.setState({ isEditorShown: !this.state.isEditorShown }); } render() { const { appContainer } = this.props; const user = appContainer.currentUser; const isLoggedIn = user != null; if (!isLoggedIn) { return ; } return ( { !this.state.isEditorShown && (
{ !this.state.isEditorShown && ( ) }
) } { this.state.isEditorShown && ( ) }
); } } /** * Wrapper component for using unstated */ const CommentEditorLazyRendererWrapper = (props) => { return createSubscribedElement(CommentEditorLazyRenderer, props, [AppContainer]); }; CommentEditorLazyRenderer.propTypes = { appContainer: PropTypes.instanceOf(AppContainer).isRequired, }; export default CommentEditorLazyRendererWrapper;