<commit_before>import React, { Component } from 'react';
import { Link, Redirect } from 'react-router-dom';
import axios from 'axios';
import Button from '../Shared/Button';
import legitCatImage from '../../images/legit-cat.png';

class GroupNames extends Component {
  constructor(props) {
    super(props)
    this.state = {
      names: ['', '']
    }
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleNameChange(i, e) {
    const { names } = this.state;
    names[i] = e.target.value;

    // If the last field has text, add another field to the end.
    if (names[names.length - 1] !== '') names.push('');
    this.setState({ names });
  }

  handleSubmit(e) {
    e.preventDefault();
    console.log(typeof this.state.names, this.state.names, this.props.match.params.id);
    let thiz = this;
    console.log(this.state.names);
    // save group to groups table, names to reviewers table, and review to review table
    // TODO persist / find a way to access the review_id for all the questions
    axios.post('/api/add-group', {
      names: this.state.names,
      // group_name: '', // in the future, we could let students name their team.
      mission_id: this.props.match.params.id,
    })
    .then((res) => {
      console.log("group added", res)
      thiz.setState({ submitGroup: true })
    })
    .catch((err) => {
      console.log("error in adding group: ", err)
      // TODO Remove: even when submit doesn't work, let's fake it for now.
      thiz.setState({ submitGroup: true })
    });
  }

  // TODO
  // Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the GroupNames component.

  render() {
    const { id, casefile_id } = this.props.match.params;
    return (
      <div className="GroupNames">
        {this.state.submitGroup && (<commit_msg>update state to hold review id on group create<commit_after>import React, { Component } from 'react';
import { Link, Redirect } from 'react-router-dom';
import axios from 'axios';
import Button from '../Shared/Button';
import legitCatImage from '../../images/legit-cat.png';

class GroupNames extends Component {
  constructor(props) {
    super(props)
    this.state = {
      names: ['', '']
    }
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleNameChange(i, e) {
    const { names } = this.state;
    names[i] = e.target.value;

    // If the last field has text, add another field to the end.
    if (names[names.length - 1] !== '') names.push('');
    this.setState({ names });
  }

  handleUpdateReviewId(reviewId) {
    this.props.updateReviewId(reviewId);
  }

  handleSubmit(e) {
    e.preventDefault();
    console.log(typeof this.state.names, this.state.names, this.props.match.params.id);
    let thiz = this;
    console.log(this.state.names);
    // save group to groups table, names to reviewers table, and review to review table
    axios.post('/api/add-group', {
      names: this.state.names,
      mission_id: this.props.match.params.id,
      // group_name: '', // in the future, we could let students name their team.
    })
    .then((res) => {
      console.log("group added", res)
      this.handleUpdateReviewId(res.data.group_id);
      thiz.setState({ submitGroup: true });
    })
    .catch((err) => {
      console.log("error in adding group: ", err)
      // TODO Remove: even when submit doesn't work, let's fake it for now.
      thiz.setState({ submitGroup: true })
    });
  }

  render() {
    const { id, casefile_id } = this.props.match.params;
    return (
      <div className="GroupNames">
        {this.state.submitGroup && (
{'fraction_non_alphanumeric': 0.1431266846361186, 'fraction_numerical': 0.0005390835579514825, 'mean_word_length': 2.825773195876289, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4618404', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1132, 'n_words': 325}