<commit_before>import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { feedbackStyle } from './ReplyFeedback.styles';

export default class ReplyFeedback extends PureComponent {
  static propTypes = {
    authId: PropTypes.string,
    replyConnection: PropTypes.object.isRequired,
    onVote: PropTypes.func.isRequired,
  };

  state = {
    isOwnReply: false,
  };

  componentWillUpdate = nextProps => {
    // check is own reply or not
    if (!this.props.authId && nextProps.authId) {
      const replyUserId = this.props.replyConnection.getIn(['user', 'id']);
      this.setState({
        isOwnReply: replyUserId === nextProps.authId,
      });
    }
  };

  handleUpVote = () => {
    const { replyConnection, onVote } = this.props;
    return onVote(replyConnection, 'UPVOTE');
  };

  handleDownVote = () => {
    const { replyConnection, onVote } = this.props;
    return onVote(replyConnection, 'DOWNVOTE');
  };

  getFeedbackScore = () => {
    const { isOwnReply } = this.state;
    return this.props.replyConnection.get('feedbacks').reduce(
      (agg, feedback) => {
        const isOwnFeedback =
          !isOwnReply && feedback.getIn(['user', 'id']) === this.props.authId;

        switch (feedback.get('score')) {
          case 1:
            agg.positiveCount += 1;
            isOwnFeedback && (agg.ownVote = 1);
            break;
          case -1:
            agg.negativeCount += 1;
            isOwnFeedback && (agg.ownVote = -1);
        }

        return agg;
      },
      { positiveCount: 0, negativeCount: 0, ownVote: 0 }
    );
  };

  render() {
    const { isOwnReply } = this.state;
    const { positiveCount, negativeCount, ownVote } = this.getFeedbackScore();
    return (
      <div className="reply-feedback">
        {!isOwnReply && <label>是否有幫助？</label>}
        <span className="vote-num">{positiveCount}</span>
        <button
          className="btn-vote"<commit_msg>Remove compoentWillUpdate because we upgraded to React 16.4<commit_after>import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { feedbackStyle } from './ReplyFeedback.styles';

export default class ReplyFeedback extends PureComponent {
  static propTypes = {
    authId: PropTypes.string,
    replyConnection: PropTypes.object.isRequired,
    onVote: PropTypes.func.isRequired,
  };

  /**
   * @returns {boolean} if the reply connection is created by the current user
   */
  isOwnReply = () => {
    const { replyConnection, authId } = this.props;
    return authId === replyConnection.getIn(['user', 'id']);
  };

  handleUpVote = () => {
    const { replyConnection, onVote } = this.props;
    return onVote(replyConnection, 'UPVOTE');
  };

  handleDownVote = () => {
    const { replyConnection, onVote } = this.props;
    return onVote(replyConnection, 'DOWNVOTE');
  };

  getFeedbackScore = () => {
    return this.props.replyConnection.get('feedbacks').reduce(
      (agg, feedback) => {
        const isOwnFeedback =
          !this.isOwnReply() &&
          feedback.getIn(['user', 'id']) === this.props.authId;

        switch (feedback.get('score')) {
          case 1:
            agg.positiveCount += 1;
            isOwnFeedback && (agg.ownVote = 1);
            break;
          case -1:
            agg.negativeCount += 1;
            isOwnFeedback && (agg.ownVote = -1);
        }

        return agg;
      },
      { positiveCount: 0, negativeCount: 0, ownVote: 0 }
    );
  };

  render() {
    const { positiveCount, negativeCount, ownVote } = this.getFeedbackScore();
    const isOwnReply = this.isOwnReply();
    return (
      <div className="reply-feedback">
        {!isOwnReply && <label>是否有幫助？</label>}
        <span className="vote-num">{positiveCount}</span>
        <button
          className="btn-vote"
{'fraction_non_alphanumeric': 0.13968087889092337, 'fraction_numerical': 0.005493068270991368, 'mean_word_length': 2.6177861873226114, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3921062', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1162, 'n_words': 246}