<commit_before>import React, {Component} from 'react';
import axios from 'axios';

import DogImage from './dogImage';
import DogSelect from './dogSelect';

export default class RandomizedMultiselect extends Component {
  constructor(props) {
    super(props);
    this.state = {
      breeds: [],
      selectedBreeds: [],
      imageUrl: ""
    };
    this.getDogBreeds = this.getDogBreeds.bind(this);
    this.getImageForBreed = this.getImageForBreed.bind(this);
    this.getImageForSelectedBreed = this.getImageForSelectedBreed.bind(this);
    this.updateSelectedBreeds = this.updateSelectedBreeds.bind(this);
  }
  getDogBreeds() {
    let url = "https://dog.ceo/api/breeds/list";
    axios.get(url)
    .then(function(res) {
      this.setState({
        breeds: res.data.message
      });
    }.bind(this))
    .catch(function(err) {
      console.error(err);
    }.bind(this));
  }
  getImageForBreed(breed) {
    let url = "https://dog.ceo/api/breed/" + breed + "/images/random";
    axios.get(url)
    .then(function(res) {
      this.setState({
        imageUrl: res.data.message
      });
    }.bind(this))
    .catch(function(err) {
      console.error(err);
    }.bind(this));
  }
  getFromSelectedBreeds() {
    let breeds = this.state.selectedBreeds;
    let index = Math.floor(Math.random() * breeds.length);
    return breeds[index];
  }
  getImageForSelectedBreed() {
    let breed = this.getFromSelectedBreeds();
    this.getImageForBreed(breed);
  }
  updateSelectedBreeds(breeds) {
    this.setState({
      selectedBreeds: breeds
    });
    this.getImageForBreed(breeds[breeds.length-1]);
  }
  getButtonDisabled(){
    return this.state.selectedBreeds.length === 0;
  }
  render() {
    if(this.state.breeds.length === 0) {
      this.getDogBreeds();
    }
    let isButtonDisabled = this.getButtonDisabled();
    return (
      <div className="randomized-multiselect">
        <div className="columns">
          <div className="column is-half">
            <DogSelect data={this.state.breeds} handleChange={this.updateSelectedBreeds}/>
            <a className="button is-primary is-fullwidth" onClick={this.getImageForSelectedBreed} disabled={isButtonDisabled}>Another One!</a>
          </div>
          <div className="column is-half">
            <DogImage data={this.state.imageUrl}/>
          </div>
        </div>
      </div>
    );
  }
}<commit_msg>button now spins if an image is loading<commit_after>import React, {Component} from 'react';
import axios from 'axios';

import DogImage from './dogImage';
import DogSelect from './dogSelect';

export default class RandomizedMultiselect extends Component {
  constructor(props) {
    super(props);
    this.state = {
      breeds: [],
      selectedBreeds: [],
      imageUrl: "",
      loadingSelectedItemData: false
    };
    this.getDogBreeds = this.getDogBreeds.bind(this);
    this.getImageForBreed = this.getImageForBreed.bind(this);
    this.getImageForSelectedBreed = this.getImageForSelectedBreed.bind(this);
    this.updateSelectedBreeds = this.updateSelectedBreeds.bind(this);
  }
  getDogBreeds() {
    let url = "https://dog.ceo/api/breeds/list";
    axios.get(url)
    .then(function(res) {
      this.setState({
        breeds: res.data.message
      });
    }.bind(this))
    .catch(function(err) {
      console.error(err);
    }.bind(this));
  }
  getImageForBreed(breed) {
    let url = "https://dog.ceo/api/breed/" + breed + "/images/random";
    this.setState({ loadingSelectedItemData: true });

    axios.get(url)
    .then(function(res) {
      this.setState({
        imageUrl: res.data.message,
        loadingSelectedItemData: false
      });
    }.bind(this))
    .catch(function(err) {
      console.error(err);
    }.bind(this));
  }
  getFromSelectedBreeds() {
    let breeds = this.state.selectedBreeds;
    let index = Math.floor(Math.random() * breeds.length);
    return breeds[index];
  }
  getImageForSelectedBreed() {
    let breed = this.getFromSelectedBreeds();
    this.getImageForBreed(breed);
  }
  updateSelectedBreeds(breeds) {
    this.setState({
      selectedBreeds: breeds
    });
    this.getImageForBreed(breeds[breeds.length-1]);
  }
  getButtonClass(){
    let extraClass = (this.state.loadingSelectedItemData) ? 'is-loading' : '';
    return 'button is-primary is-fullwidth ' + extraClass;
  }
  getButtonDisabled(){
    return this.state.selectedBreeds.length === 0;
  }
  render() {
    if(this.state.breeds.length === 0) {
      this.getDogBreeds();
    }
    let buttonClass = this.getButtonClass();
    let isButtonDisabled = this.getButtonDisabled();
    return (
      <div className="randomized-multiselect">
        <div className="columns">
          <div className="column is-half">
            <DogSelect data={this.state.breeds} handleChange={this.updateSelectedBreeds}/>
            <a className={buttonClass} onClick={this.getImageForSelectedBreed} disabled={isButtonDisabled}>Go</a>
          </div>
          <div className="column is-half">
            <DogImage data={this.state.imageUrl}/>
          </div>
        </div>
      </div>
    );
  }
}
{'fraction_non_alphanumeric': 0.14333268063442334, 'fraction_numerical': 0.0011748580379870766, 'mean_word_length': 2.9535603715170278, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 4, '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': '5650171', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1625, 'n_words': 270}