<commit_before>import $ from 'jquery';
import React, {Component} from 'react';
import SidebarFilter from './SidebarFilter.jsx';
import BuildsSidebarMessage from './BuildsSidebarMessage.jsx';
import {bindAll, has} from 'underscore';
import {getFilterMatches} from '../../utils/buildsHelpers';
import {FILTER_MESSAGES, NO_MATCH_MESSAGES} from '../constants';
import Loader from '../shared/Loader.jsx';
import LazyRender from '../shared/LazyRender.jsx';
import SidebarItem from './SidebarItem.jsx';

let Link = require('react-router').Link;

import BuildsStore from '../../stores/buildsStore';
import BuildsActions from '../../actions/buildsActions';
import StarStore from '../../stores/starStore';
import StarActions from '../../actions/starActions';

import GlobalBuildsStore from '../../stores/globalBuildsStore';
import GlobalBuildsActions from '../../actions/globalBuildsActions';

import Sidebar from './Sidebar.jsx';

class BuildsSidebarContainer extends Component {

  constructor(props) {
    super(props);
    
    bindAll(this, 'persistStarChange', 'onBuildsStatusChange', 'getBuildsOfType', 'updateResults', 'setToggleState');

    this.state = {
      builds: [],
      loadingBuilds: true,
      loadingStars: true,
      loading: true,
      changingBuildsType: false,
      filterText: '',
      toggleFilterState: 'starred',
      sidebarHeight: $(window).height() - $('#primary-nav').height() + $('.sidebar__filter').height()
    };
  }

  componentDidMount() {
    StarActions.loadStars('sidebar');

    this.unsubscribeFromStars = StarStore.listen(this.onBuildsStatusChange);
    //
    // temporarily load global builds until we have a searchable endpoint
    this.unsubscribeFromGlobalBuilds = GlobalBuildsStore.listen(this.onBuildsStatusChange);
    //
    
    this.unsubscribeFromStarredBuilds = BuildsStore.listen(this.onBuildsStatusChange);
    BuildsActions.loadBuilds(this.state.toggleFilterState);
    // initially load global builds so we have quick access
    // we will remove this when we have a searchable endpoint
    GlobalBuildsActions.loadBuildsOnce();
    //
  }

  componentWillUnmount() {
    BuildsActions.stopListening();
    this.unsubscribeFromStarredBuilds();
  }
  
  // fetch builds based on toggle selection
  getBuildsOfType(type) {
    this.setState({
      changingBuildsType: true
    });

    //
    // Temporary until we have a searchable endpoint
    if (type === 'all') {
      BuildsActions.setFilterType('all');
      BuildsActions.stopListening();
      GlobalBuildsActions.loadBuilds();
    }
    else {
      GlobalBuildsActions.stopPolling();
      BuildsActions.loadBuildOfType(type);
    }
    
  }

  onBuildsStatusChange(state) {
    if (state.filterHasChanged) {
      state.changingBuildsType = false;
    }<commit_msg>update sidebar size calculation on resize<commit_after>import $ from 'jquery';
import React, {Component} from 'react';
import SidebarFilter from './SidebarFilter.jsx';
import BuildsSidebarMessage from './BuildsSidebarMessage.jsx';
import {bindAll, has, debounce} from 'underscore';
import {getFilterMatches} from '../../utils/buildsHelpers';
import {FILTER_MESSAGES, NO_MATCH_MESSAGES} from '../constants';
import Loader from '../shared/Loader.jsx';
import LazyRender from '../shared/LazyRender.jsx';
import SidebarItem from './SidebarItem.jsx';

let Link = require('react-router').Link;

import BuildsStore from '../../stores/buildsStore';
import BuildsActions from '../../actions/buildsActions';
import StarStore from '../../stores/starStore';
import StarActions from '../../actions/starActions';

import GlobalBuildsStore from '../../stores/globalBuildsStore';
import GlobalBuildsActions from '../../actions/globalBuildsActions';

import Sidebar from './Sidebar.jsx';

class BuildsSidebarContainer extends Component {

  constructor(props) {
    super(props);
    
    bindAll(this, 
      'persistStarChange', 
      'onBuildsStatusChange', 
      'getBuildsOfType', 
      'updateResults', 
      'setToggleState'
    );

    this.state = {
      builds: [],
      loadingBuilds: true,
      loadingStars: true,
      loading: true,
      changingBuildsType: false,
      filterText: '',
      toggleFilterState: 'starred',
      sidebarHeight: this.getSidebarHeight()
    };
  }

  componentWillMount() {
    this.handleResizeDebounced = debounce(() => {
      this.setState({
        sidebarHeight: this.getSidebarHeight()
      });
    }, 500);
  }

  componentDidMount() {
    StarActions.loadStars('sidebar');

    this.unsubscribeFromStars = StarStore.listen(this.onBuildsStatusChange);
    //
    // temporarily load global builds until we have a searchable endpoint
    this.unsubscribeFromGlobalBuilds = GlobalBuildsStore.listen(this.onBuildsStatusChange);
    //
    
    this.unsubscribeFromStarredBuilds = BuildsStore.listen(this.onBuildsStatusChange);
    BuildsActions.loadBuilds(this.state.toggleFilterState);
    // initially load global builds so we have quick access
    // we will remove this when we have a searchable endpoint
    GlobalBuildsActions.loadBuildsOnce();
    
    window.addEventListener('resize', this.handleResizeDebounced);
  }

  componentWillUnmount() {
    BuildsActions.stopListening();
    this.unsubscribeFromStarredBuilds();
    window.removeEventListener('resize', this.handleResizeDebounced);
  }
  
  getSidebarHeight() {
    return $(window).height() - $('#primary-nav').height() + $('.sidebar__filter').height();
  }

  // fetch builds based on toggle selection
  getBuildsOfType(type) {
    this.setState({
      changingBuildsType: true
    });

    //
    // Temporary until we have a searchable endpoint
    if (type === 'all') {
      BuildsActions.setFilterType('all');
      BuildsActions.stopListening();
      GlobalBuildsActions.loadBuilds();
    }
    else {
      GlobalBuildsActions.stopPolling();
      BuildsActions.loadBuildOfType(type);
    }
    
  }

  onBuildsStatusChange(state) {
    if (state.filterHasChanged) {
      state.changingBuildsType = false;
    }
{'fraction_non_alphanumeric': 0.12539445274871283, 'fraction_numerical': 0.0004982561036372695, 'mean_word_length': 3.6039755351681957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1463250', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1731, 'n_words': 370}