<commit_before>import React from "react";
import Console from './Console.jsx';
import BuildRow from '../BuildRow.jsx'
import ActionButton from './../../lib/ActionButton.jsx';
import FaviconHelper from './../../mixins/FaviconHelper.jsx';
import simpleStorage from './../../../vendor/simpleStorage.js';
require('./build.less');
export default  React.createClass({
  mixins: [FaviconHelper],
  componentDidMount(){
    this._fetchBuild()
  },
  componentDidUpdate(){
    if(this._getBuildResult() == 'IN_PROGRESS' ){
      this._setRefreshTimer();
    }else{
      this._clearRefreshTimer();
      this._webNotifyCompletion();
    }
    this.setFavicon(this._getBuildResult());
  },
  componentWillUnmount: function() {
    this._clearRefreshTimer(); 
  },
  _getBuildResult(){
    return this.props.build && this.props.build.get('result')
  },
  _setRefreshTimer(){
    if(!this.refreshTimer){
      this.refreshTimer = setInterval(this._fetchBuild, 5000);
    }
  },
  _clearRefreshTimer(){
    if(this.refreshTimer) clearInterval(this.refreshTimer);
  },
  _fetchBuild(){
    const actions = this.props.flux.getActions('app');
    actions.currentBuildChanged(this.props.url);
  },
  render(){
    return this.props.build? (<div id="build">
      {this._buildActions()}
      <BuildRow  build={this.props.build}/>
      <Console log={this.props.build.get('log')}/>
    </div>):<div/>;
  },
  _buildActions(){
    return  this.props.build.get('cancelable')? this._inProgressActions():[this._restartButton()];
  },
  _inProgressActions(){
    return [this._cancelButton(), this_watchButton()];
  },
  _watchButton(){
    return this._supportsNotifications()?<ActionButton ref="watchButton" onClick={this._watchBuild} tooltip="Notify when done( web notification)" icon="fa fa-eye"/>: <span/>;
  },
  _supportsNotifications(){
    return simpleStorage.canUse() && ("Notification" in window);
  },
  _watchBuild(e){
    Notification.requestPermission((result)=>{
      if(result == 'granted'){
        this.refs.watchButton.disable();
        const url = this.props.build.get('cancelUrl')
        simpleStorage.set(url, true, {TTL: 7200000}) // 2 hrs
      }
    });
  },
  _webNotifyCompletion(){<commit_msg>set Favicon only if build is available'<commit_after>import React from "react";
import Console from './Console.jsx';
import BuildRow from '../BuildRow.jsx'
import ActionButton from './../../lib/ActionButton.jsx';
import FaviconHelper from './../../mixins/FaviconHelper.jsx';
import simpleStorage from './../../../vendor/simpleStorage.js';
require('./build.less');
export default  React.createClass({
  mixins: [FaviconHelper],
  componentDidMount(){
    this._fetchBuild()
  },
  componentDidUpdate(){
    if(this._getBuildResult() == 'IN_PROGRESS' ){
      this._setRefreshTimer();
    }else{
      this._clearRefreshTimer();
      this._webNotifyCompletion();
    }
    if(this.build){
      this.setFavicon(this._getBuildResult());
    }
  },
  componentWillUnmount: function() {
    this._clearRefreshTimer(); 
  },
  _getBuildResult(){
    return this.props.build && this.props.build.get('result')
  },
  _setRefreshTimer(){
    if(!this.refreshTimer){
      this.refreshTimer = setInterval(this._fetchBuild, 5000);
    }
  },
  _clearRefreshTimer(){
    if(this.refreshTimer) clearInterval(this.refreshTimer);
  },
  _fetchBuild(){
    const actions = this.props.flux.getActions('app');
    actions.currentBuildChanged(this.props.url);
  },
  render(){
    return this.props.build? (<div id="build">
      {this._buildActions()}
      <BuildRow  build={this.props.build}/>
      <Console log={this.props.build.get('log')}/>
    </div>):<div/>;
  },
  _buildActions(){
    return  this.props.build.get('cancelable')? this._inProgressActions():[this._restartButton()];
  },
  _inProgressActions(){
    return [this._cancelButton(), this._watchButton()];
  },
  _watchButton(){
    return this._supportsNotifications()?<ActionButton ref="watchButton" onClick={this._watchBuild} tooltip="Notify when done( web notification)" icon="fa fa-eye"/>: <span/>;
  },
  _supportsNotifications(){
    return simpleStorage.canUse() && ("Notification" in window);
  },
  _watchBuild(e){
    Notification.requestPermission((result)=>{
      if(result == 'granted'){
        this.refs.watchButton.disable();
        const url = this.props.build.get('cancelUrl')
        simpleStorage.set(url, true, {TTL: 7200000}) // 2 hrs
      }
    });
  },
  _webNotifyCompletion(){
{'fraction_non_alphanumeric': 0.17193454382425466, 'fraction_numerical': 0.005379959650302623, 'mean_word_length': 3.751863684771033, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '5990783', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1372, 'n_words': 232}