<commit_before>import * as ServerAPI from '../serverAPI';

import Diacritics from 'diacritics';
import FilterBar from './FilterBar';
import { Loader } from 'semantic-ui-react';
import Pagination from './Pagination';
import React from 'react';
import ResourceList from './ResourceList';
import _ from 'lodash';

export default class ParliamentApp extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      parliamentarians: [],
      pageSize: 25,
      page: 1,
      isLoading: true,
      searchName: '',
      searchState: 'any',
      searchParty: 'any',
      parties: [],
      states: [],
    };

    this.handlePageChange = this.handlePageChange.bind(this);
    this.handleSearchParliamentary = this.handleSearchParliamentary.bind(this);
  }


  componentWillMount() {
    let resource = this.props.route.path;
    this.loadResourceFromServer(resource);
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.route.path !== nextProps.route.path) {
      let resource = nextProps.route.path;
      this.loadResourceFromServer(resource);
    }
  }

  loadResourceFromServer(resource) {
    ServerAPI.getResource(resource).then((parliamentarians) => {
      let states = [];
      let parties = [];

      parliamentarians.forEach((parliamentary) => {
        parties.push(parliamentary.party);
        states.push(parliamentary.state);
      })

      parliamentarians = _.sortBy(parliamentarians, 'name');
      parties = [...new Set(parties)].sort();
      states = [...new Set(states)].sort();

      this.setState({
        parliamentarians,
        isLoading: false,
        parties,
        states
      });
    }).catch((error) => {<commit_msg>Fix loading when props is updated withou mount<commit_after>import * as ServerAPI from '../serverAPI';

import Diacritics from 'diacritics';
import FilterBar from './FilterBar';
import { Loader } from 'semantic-ui-react';
import Pagination from './Pagination';
import React from 'react';
import ResourceList from './ResourceList';
import _ from 'lodash';

export default class ParliamentApp extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      parliamentarians: [],
      pageSize: 25,
      page: 1,
      isLoading: true,
      searchName: '',
      searchState: 'any',
      searchParty: 'any',
      parties: [],
      states: [],
    };

    this.handlePageChange = this.handlePageChange.bind(this);
    this.handleSearchParliamentary = this.handleSearchParliamentary.bind(this);
  }


  componentWillMount() {
    let resource = this.props.route.path;
    this.loadResourceFromServer(resource);
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.route.path !== nextProps.route.path) {
      this.setState({isLoading: true});
      let resource = nextProps.route.path;
      this.loadResourceFromServer(resource);
    }
  }

  loadResourceFromServer(resource) {
    ServerAPI.getResource(resource).then((parliamentarians) => {
      let states = [];
      let parties = [];

      parliamentarians.forEach((parliamentary) => {
        parties.push(parliamentary.party);
        states.push(parliamentary.state);
      })

      parliamentarians = _.sortBy(parliamentarians, 'name');
      parties = [...new Set(parties)].sort();
      states = [...new Set(states)].sort();

      this.setState({
        parliamentarians,
        isLoading: false,
        parties,
        states
      });
    }).catch((error) => {
{'fraction_non_alphanumeric': 0.13266187050359712, 'fraction_numerical': 0.0017266187050359713, 'mean_word_length': 3.0278099652375436, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1198237', 'n_tokens_mistral': 1010, 'n_tokens_neox': 998, 'n_words': 203}