<commit_before>
// eslint-disable-next-line
import React, { Component } from 'react';

import Autosuggest from 'react-autosuggest';

// eslint-disable-next-line
import 'element-theme-default';


import { ipcRenderer } from 'electron';

import './App.css';

import { BottomItem } from './components/helper';
import Caret from './components/caret';
import PastItems from './components/pastItems';

// const getPercentage = (start, end, base = 28800000) => Math.round(base / (new Date(end) - new Date(start)));


function putOngoing(obj) {
  window.localStorage.setItem('ongoing-item', JSON.stringify(obj));
}
function getOngoing() {
  const ongoing = window.localStorage.getItem('ongoing-item');
  if (ongoing) {
    return JSON.parse(ongoing);
  }
  return null;
}

function renderSuggestion(suggestion) {
  return (
    <div style={{ cursor: 'pointer' }}>
      <span style={{
        fontSize: '13px',
        width: '100%',
        float: 'left',
        clear: 'both',
      }}
      >{suggestion.hint}</span>
      <span style={{
        fontSize: '11px',
        color: '#717171',
      }}
      >{suggestion.description}</span>
    </div>
  );
}

const hrStyle = {
  display: 'block',
  height: '1px',
  border: 0,
  borderTop: '1px solid rgb(173, 173, 173)',
  margin: '0 0 -1px',
  padding: 0,
};

const slashHints = [{
  hint: '/hi',
  description: 'start working',
  id: 'hi',
  create: name => ({ k: `${Date.now()}hi`, name, created: new Date().toISOString(), type: 'hi' }),
}, {
  hint: '/bye',
  description: 'end working',
  id: 'bye',
  create: name => ({ k: `${Date.now()}bye`, name, created: new Date().toISOString(), type: 'bye' }),
}, {
  hint: '/break',
  description: 'take a break from working',
  id: 'break',
  create: name => ({ k: `${Date.now()}bye`, name, created: new Date().toISOString(), type: 'break' }),
}];


class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      timeInput: '',
      pastItems: [],
      hints: slashHints,
      interval: null,
      h: 0,
    };

    this.addTime = this.addTime.bind(this);
    this.onInputChange = this.onInputChange.bind(this);
    this.onSuggestionsClearRequested = this.onSuggestionsClearRequested.bind(this);
    this.stopIntervalUpdate = this.stopIntervalUpdate.bind(this);
    this.startIntervalUpdate = this.startIntervalUpdate.bind(this);
  }

  componentWillMount() {
    this.startIntervalUpdate();
  }

  componentDidMount() {
    if (this.inputField) {
      this.inputField.focus();
    }
    window.addEventListener('focus', () => this.inputField && this.inputField.focus());
    document.addEventListener('keydown', (event) => {
      // ESC
      if (event.keyCode === 27) {
        event.stopPropagation();
        event.preventDefault();
        ipcRenderer.send('hide-app');
      }
    });

    console.log('sending', 'get-entries');

    // load possible latest ongoing
    const ongoing = getOngoing();

    ipcRenderer.on('get-entries-resp', (event, data) => {
      console.log({ data });
      if (ongoing) {
        data.push(ongoing);
      }
      this.setState({
        pastItems: data,
      });
    });
    ipcRenderer.send('get-entries');
  }

  componentWillUnmount() {
    this.stopIntervalUpdate();
  }

  onInputChange(event, { newValue, method }) {
    console.log({ newValue, method });
    const changeHintList = method !== 'down' && method !== 'up';<commit_msg>stop interval timer if app is hidden<commit_after>
// eslint-disable-next-line
import React, { Component } from 'react';

import Autosuggest from 'react-autosuggest';

// eslint-disable-next-line
import 'element-theme-default';


import { ipcRenderer } from 'electron';

import './App.css';

import { BottomItem } from './components/helper';
import Caret from './components/caret';
import PastItems from './components/pastItems';

// const getPercentage = (start, end, base = 28800000) => Math.round(base / (new Date(end) - new Date(start)));


function putOngoing(obj) {
  window.localStorage.setItem('ongoing-item', JSON.stringify(obj));
}
function getOngoing() {
  const ongoing = window.localStorage.getItem('ongoing-item');
  if (ongoing) {
    return JSON.parse(ongoing);
  }
  return null;
}

function renderSuggestion(suggestion) {
  return (
    <div style={{ cursor: 'pointer' }}>
      <span style={{
        fontSize: '13px',
        width: '100%',
        float: 'left',
        clear: 'both',
      }}
      >{suggestion.hint}</span>
      <span style={{
        fontSize: '11px',
        color: '#717171',
      }}
      >{suggestion.description}</span>
    </div>
  );
}

const hrStyle = {
  display: 'block',
  height: '1px',
  border: 0,
  borderTop: '1px solid rgb(173, 173, 173)',
  margin: '0 0 -1px',
  padding: 0,
};

const slashHints = [{
  hint: '/hi',
  description: 'start working',
  id: 'hi',
  create: name => ({ k: `${Date.now()}hi`, name, created: new Date().toISOString(), type: 'hi' }),
}, {
  hint: '/bye',
  description: 'end working',
  id: 'bye',
  create: name => ({ k: `${Date.now()}bye`, name, created: new Date().toISOString(), type: 'bye' }),
}, {
  hint: '/break',
  description: 'take a break from working',
  id: 'break',
  create: name => ({ k: `${Date.now()}bye`, name, created: new Date().toISOString(), type: 'break' }),
}];


class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      timeInput: '',
      pastItems: [],
      hints: slashHints,
      interval: null,
      h: 0,
    };

    this.addTime = this.addTime.bind(this);
    this.onInputChange = this.onInputChange.bind(this);
    this.onSuggestionsClearRequested = this.onSuggestionsClearRequested.bind(this);
    this.stopIntervalUpdate = this.stopIntervalUpdate.bind(this);
    this.startIntervalUpdate = this.startIntervalUpdate.bind(this);
  }

  componentWillMount() {
    this.startIntervalUpdate();
  }

  componentDidMount() {
    if (this.inputField) {
      this.inputField.focus();
    }
    window.addEventListener('focus', () => this.inputField && this.inputField.focus());
    document.addEventListener('keydown', (event) => {
      // ESC
      if (event.keyCode === 27) {
        event.stopPropagation();
        event.preventDefault();
        ipcRenderer.send('hide-app');
      }
    });

    console.log('sending', 'get-entries');

    // load possible latest ongoing
    const ongoing = getOngoing();

    ipcRenderer.on('get-entries-resp', (event, data) => {
      console.log({ data });
      if (ongoing) {
        data.push(ongoing);
      }
      this.setState({
        pastItems: data,
      });
    });
    ipcRenderer.send('get-entries');


    ipcRenderer.on('app-isgoingto-hide', () => {
      console.log('received app-isgoingto-hide');
      if (this.state.interval) {
        this.stopIntervalUpdate();
      }
    });
    ipcRenderer.on('app-isgoingto-show', () => {
      console.log('received app-isgoingto-show');
      if (!this.state.interval) {
        this.startIntervalUpdate();
      }
    });
  }

  componentWillUnmount() {
    this.stopIntervalUpdate();
  }

  onInputChange(event, { newValue, method }) {
    console.log({ newValue, method });
    const changeHintList = method !== 'down' && method !== 'up';
{'fraction_non_alphanumeric': 0.1740633208903636, 'fraction_numerical': 0.011060417530761786, 'mean_word_length': 3.0481253497481813, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, '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': '2315046', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2332, 'n_words': 493}