<commit_before>import React, {Component} from "react";
import {Button} from 'react-bootstrap';
import PropTypes from 'prop-types';




export default class QoodleDetails extends Component {



  constructor(){
    super();

    this.state =
    {
      nome : "",//nome qoodle che mi hanno passato
      usrname: "",
      elements: [
        {
          what: "pere",
          whos: [
            {name: "example.com", count: 5 },
            {name: "<EMAIL>", count: 3}
          ]
      },
      {
        what: "mele",
        whos: [
          {name: "ex2.com", count: 4 },
          {name: "<EMAIL>", count: 15}
        ]
    }
      ]
    }
  }

  static defaultProps =
  {
    purchase: true
  }




  componentDidMount()
  {
    var id;
    if (typeof window !== 'undefined')
      id = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

    var url = 'http://' + process.env.REACT_APP_SPECIFIC_ID + ':4567/details/' + id;
    var myInit = {
          method: 'get',
          mode: 'cors',
          headers: {
            'Content-Type': 'application/json'
          },
        };

        var nameLogged = "exampleUser";
        if( window.gapi && window.gapi.auth2 && window.gapi.auth2.getAuthInstance() && !(window.gapi.auth2.getAuthInstance().currentUser === "undefined"))
          nameLogged = window.gapi.auth2.getAuthInstance().currentUser.Ab.profileObj.email;

    fetch(url, myInit)
    .then( function(response) {
      if(response.ok)
      return response.json();
      throw new Error("Network response was not ok")
    })
    .then(function(data)
        { this.setState({
          nome: data.nome,
          elements: data.elements,
          username: nameLogged
          });
    }
    .bind(this))
    .catch((error) => { console.error(error); });;

  }




  renderPeople(whos)
  {
    return (   whos.map( (who) => <div key={who.name}> - {who.name}  ( {who.count}  ) </div>)   );
  }


  renderElement()
  {

    return (
    <div>
    {this.state.elements.map( (ele) => <div key={ele.what}> <div className="elements"> elemento : {ele.what} (  {ele.whos.reduce( (pv, cv) => pv + cv.count , 0)}  )</div> <div>{this.renderPeople(ele.whos)}</div>  </div> )}<commit_msg>aggiunto che fetch elementi<commit_after>import React, {Component} from "react";
import {Button} from 'react-bootstrap';
import PropTypes from 'prop-types';




export default class QoodleDetails extends Component {



  constructor(){
    super();

    this.state =
    {
      nome : "",//nome qoodle che mi hanno passato
      usrname: "",
      elements: null
    }
  }

  static defaultProps =
  {
    purchase: true
  }




  componentDidMount()
  {
    var id;
    if (typeof window !== 'undefined')
      id = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

    var url = 'http://' + process.env.REACT_APP_SPECIFIC_ID + ':4567/details/' + id;
    var myInit = {
          method: 'get',
          mode: 'cors',
          headers: {
            'Content-Type': 'application/json'
          },
        };

        var nameLogged = "exampleUser";
        if( window.gapi && window.gapi.auth2 && window.gapi.auth2.getAuthInstance() && !(window.gapi.auth2.getAuthInstance().currentUser === "undefined"))
          nameLogged = window.gapi.auth2.getAuthInstance().currentUser.Ab.profileObj.email;

    fetch(url, myInit)
    .then( function(response) {
      if(response.ok)
      return response.json();
      throw new Error("Network response was not ok")
    })
    .then(function(data)
        { this.setState({
          nome: data.nome,
          elements: data.elements,
          username: nameLogged
          });
    }
    .bind(this))
    .catch((error) => { console.error(error); });;

  }




  renderPeople(whos)
  {
    return (   whos.map( (who) => <div key={who.name}> - {who.name}  ( {who.count}  ) </div>)   );
  }


  renderElement()
  {
    var detailsList= "questo qoodle non ha elementi";
    if(this.state.elements != null)
      detailsList = (this.state.elements.map( (ele) => <div key={ele.what}> <div className="elements"> elemento : {ele.what} (  {ele.whos.reduce( (pv, cv) => pv + cv.count , 0)}  )</div> <div>{this.renderPeople(ele.whos)}</div>  </div> ));

    return (
    <div>
      {detailsList}
{'fraction_non_alphanumeric': 0.16355576294913673, 'fraction_numerical': 0.006066262249183388, 'mean_word_length': 2.2477272727272726, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, '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': '963617', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1390, 'n_words': 287}