<commit_before>import React, {Component} from "react";
import {Button} from 'react-bootstrap';
import QoodleElement from "../../components/QoodleElement";
import SummaryModal from "../../components/SummaryModal";
import InfoModal from '../../components/InfoModal';

import Timer from "../../components/Timer"
import MobileTimer from "../../components/MobileTimer"


export default class QoodleView extends Component {

  static defaultProps =
  {
    purchase: true
  }



    constructor () {
        super();



        this.state = {
          username: "",
          realName: "",
          id : 0,//ora come esempio
          showSummaryModal: false,
          showInfomModal: false,
          title: '',
          description: '',
          closingDate: new Date(),
          elements: [],
          point: 0,
          }
    }




    componentDidMount()
    {
      var token;
      var client;
      var email;
      var realNameLogged;

      if (typeof(Storage) !== "undefined")
      {
        token = sessionStorage.getItem("Idtoken");
        client = sessionStorage.getItem("IdClient");
        email = sessionStorage.getItem("email");
        realNameLogged = sessionStorage.getItem("name");
      }
      else {
        email = "exampleUser";
        realNameLogged = "realExample";
      }
            if (typeof window !== 'undefined') {
            var id = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

            this.setState({ id: id});
          }

            var url = 'http://' + process.env.REACT_APP_SPECIFIC_ID + ':4567/qoodle/' + id;
            var myInit = {
                  method: 'get',
                  mode: 'cors',
                  headers: {
                    'Content-Type': 'application/json',
                    'id_token': token,
                    'id_client': client,
                    'email': 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({
                  elements: data.ele,
                  title: data.title,
                  description: data.description,
                  closingDate: new Date (data.closingDate),
                  username: email,
                  realName: realNameLogged,
                  type: data.type,
                  point: data.type === "dem" ? 10 : 0,
                  });
            }
            .bind(this))
            .catch((error) => { console.error(error); });;



    }

    renderMobileSum()
    {
      var elementi = this.state.elements;

      var sum = 0, counterSum = 0;
      for(var i = 0; i<elementi.length; i++){
        sum += elementi[i].price * elementi[i].counter;
        counterSum += elementi[i].counter;
      }
      sum = "Continua" + "(Totale: " + sum + "€)";
      counterSum = "Conferma scelte: ( " + counterSum + " )";

      if(this.state.type === "purchase")
        return sum;
      else
        return counterSum;

    }



    renderSum()
    {
      var elementi = this.state.elements;

      var sum = 0, counterSum = 0;
      for(var i = 0; i<elementi.length; i++){
        sum += elementi[i].price * elementi[i].counter;
        counterSum += elementi[i].counter;
      }
      sum = "Procedi all'ordine " + "(Totale: " + sum + "€)";
      counterSum = "Conferma le scelte prese (sono " + counterSum + ")" ;

      if(this.state.type !== "dem")
        return sum;
      else
        return counterSum;

    }

    Inc(iden)
    {
      const elementi = this.state.elements;


<commit_msg>refactoring, dei metodi per il render del totale<commit_after>import React, {Component} from "react";
import {Button} from 'react-bootstrap';
import QoodleElement from "../../components/QoodleElement";
import SummaryModal from "../../components/SummaryModal";
import InfoModal from '../../components/InfoModal';

import Timer from "../../components/Timer"
import MobileTimer from "../../components/MobileTimer"


export default class QoodleView extends Component {

  static defaultProps =
  {
    purchase: true
  }



    constructor () {
        super();



        this.state = {
          username: "",
          realName: "",
          id : 0,//ora come esempio
          showSummaryModal: false,
          showInfomModal: false,
          title: '',
          description: '',
          closingDate: new Date(),
          elements: [],
          point: 0,
          }
    }




    componentDidMount()
    {
      var token;
      var client;
      var email;
      var realNameLogged;

      if (typeof(Storage) !== "undefined")
      {
        token = sessionStorage.getItem("Idtoken");
        client = sessionStorage.getItem("IdClient");
        email = sessionStorage.getItem("email");
        realNameLogged = sessionStorage.getItem("name");
      }
      else {
        email = "exampleUser";
        realNameLogged = "realExample";
      }
            if (typeof window !== 'undefined') {
            var id = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

            this.setState({ id: id});
          }

            var url = 'http://' + process.env.REACT_APP_SPECIFIC_ID + ':4567/qoodle/' + id;
            var myInit = {
                  method: 'get',
                  mode: 'cors',
                  headers: {
                    'Content-Type': 'application/json',
                    'id_token': token,
                    'id_client': client,
                    'email': 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({
                  elements: data.ele,
                  title: data.title,
                  description: data.description,
                  closingDate: new Date (data.closingDate),
                  username: email,
                  realName: realNameLogged,
                  type: data.type,
                  point: data.type === "dem" ? 10 : 0,
                  });
            }
            .bind(this))
            .catch((error) => { console.error(error); });;



    }

    renderSum()
    {
      var ordine = "Procedi all'ordine " + "(Totale: " ;
      var scelta = "Conferma le scelte prese (sono " ;

      return this.renderTotal(ordine, scelta);
    }

    renderMobileSum()
    {
      var ordine = "Continua" + "(Totale: ";
      var scelta = "Conferma scelte: ( ";

      return this.renderTotal(ordine, scelta);

    }

    renderTotal(ordine, scelte)
    {
      var elementi = this.state.elements;

      var sum = 0, counterSum = 0;
      for(var i = 0; i<elementi.length; i++){
        sum += elementi[i].price * elementi[i].counter;
        counterSum += elementi[i].counter;
      }


      if(this.state.type === "purchase")
        return (ordine + sum + "€)");
      else
        return (scelte + counterSum + ")");

    }


    Inc(iden)
    {
      const elementi = this.state.elements;



{'fraction_non_alphanumeric': 0.13023319241783718, 'fraction_numerical': 0.0039547252147824905, 'mean_word_length': 1.5688266199649736, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '5921253', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1990, 'n_words': 461}