{"size": 1332, "ext": "js", "max_stars_repo_path": "frontend/src/components/comments/CommentInput.js", "max_stars_repo_name": "oshinsayami/Petgram", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/src/components/comments/CommentInput.js", "max_issues_repo_name": "oshinsayami/Petgram", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/src/components/comments/CommentInput.js", "max_forks_repo_name": "oshinsayami/Petgram", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.9655172414, "max_line_length": 75, "alphanum_fraction": 0.5870870871}
import React, { Component } from 'react';
import { addComment } from '../../redux/actions/postsAction'
import {connect} from 'react-redux'


class CommentInput extends Component {

    state = {
        body: '',
        user_id: this.props.user_id,
        post_id: parseInt(this.props.postId),
        username: this.props.username
    }
    

  handleOnChange = event => {
    // this.setState({
    //   body: event.target.value,
    // });
    const {name, value} = event.target
       this.setState({
        [name]: value
       })
   }
  

  handleOnSubmit = event => {
    event.preventDefault();
    this.setState({ body: "" });
    this.props.addComment(this.state)
  }

  render() {
    return (
     <div>
        <form className="post__commentbox" onSubmit={this.handleOnSubmit} >
          <input className="post__input"
            placeholder="Add a comment"
            type="text"
            value={this.state.body}
            onChange={this.handleOnChange} name="body"/>
          <button className="post__button" type="submit" >Post</button>
        </form>
      </div>
    );
  }
    
};

const mapStateToProps = (state) => {
    return {
      user_id: state.auth.currentUser.id,
      username: state.auth.currentUser.username
    }
}

export default connect(mapStateToProps, {addComment})(CommentInput);
