<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import * as React from 'react';
import { ReportReportable } from 'report-reportable';

interface State {
  postId: string;
  username: string;
}

export default class ForumPostReport extends React.Component<{}, State> {
  state = {
    postId: '',
    username: '',
  };

  private reportRef = React.createRef<ReportReportable>();

  componentDidMount() {
    $(document).on('click', '.js-forum-post-report', this.onClickReportButton);
  }

  componentWillUnmount() {
    $(document).off('click', '.js-forum-post-report', this.onClickReportButton);
  }

  render() {
    return (
      <ReportReportable
        ref={this.reportRef}
        reportableId={this.state.postId}
        reportableType='forum_post'
        user={{ username: this.state.username }}
      />
    );
  }

  private onClickReportButton = (e: JQuery.ClickEvent<Document>) => {
    if (e.button !== 0) { return; }

    const post = e.currentTarget.closest('.js-forum-post');

    if (post == null) { return; }

    const postId = post.dataset.postId;
    const username = post.dataset.postUsername;

    if (postId == null || username == null) {
      return;
    }

    this.setState({ postId, username }, () => {
      if (this.reportRef.current != null) {
        this.reportRef.current.showForm();
      }
    });
  }
}<commit_msg>Fix incorrect message when reporting for another post<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import * as React from 'react';
import { ReportReportable } from 'report-reportable';

interface State {
  postId: string;
  username: string;
}

export default class ForumPostReport extends React.Component<{}, State> {
  state = {
    postId: '',
    username: '',
  };

  private reportRef = React.createRef<ReportReportable>();

  componentDidMount() {
    $(document).on('click', '.js-forum-post-report', this.onClickReportButton);
  }

  componentWillUnmount() {
    $(document).off('click', '.js-forum-post-report', this.onClickReportButton);
  }

  render() {
    return (
      <ReportReportable
        // Manually set key to create new form when reporting for
        // different post.
        key={this.state.postId}
        ref={this.reportRef}
        reportableId={this.state.postId}
        reportableType='forum_post'
        user={{ username: this.state.username }}
      />
    );
  }

  private onClickReportButton = (e: JQuery.ClickEvent<Document>) => {
    if (e.button !== 0) { return; }

    const post = e.currentTarget.closest('.js-forum-post');

    if (post == null) { return; }

    const postId = post.dataset.postId;
    const username = post.dataset.postUsername;

    if (postId == null || username == null) {
      return;
    }

    this.setState({ postId, username }, () => {
      if (this.reportRef.current != null) {
        this.reportRef.current.showForm();
      }
    });
  }
}
{'fraction_non_alphanumeric': 0.14226738647189585, 'fraction_numerical': 0.001905366783105748, 'mean_word_length': 2.957286432160804, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '3858826', 'n_tokens_mistral': 971, 'n_tokens_neox': 941, 'n_words': 234}