<commit_before>import { h, Component } from 'preact';
import AppConstants from '../constants/AppConstants'
import Constants from '../constants/Constants'
const config = require('../../appconfig')

let getLatest, getByDate
if (config.mode === AppConstants.DEV_MODE) {
  getLatest = require('../../test/helpers/api_fixture').getLatest
  getByDate = require('../../test/helpers/api_fixture').getByDate
} else {
  getLatest = require('../helpers/api').getLatest
  getByDate = require('../helpers/api').getByDate
}

import Wrapper from '../components/Wrapper'

import yesterday from '../helpers/yesterday'
import tomorrow from '../helpers/tomorrow'
import normalizeDate from '../helpers/normalize-date'
import randomDate from '../helpers/random-date'

class App extends Component {
  constructor(props){
    super(props)
    this.state = {
      isLoading: true,
      tries: 0,
      isFailure: false,
      showInfo: true
    }

    this.handlePreviousClick = this.handlePreviousClick.bind(this)
    this.handleNextClick = this.handleNextClick.bind(this)
    this.handleToggleClick = this.handleToggleClick.bind(this)
    this.handleRandomClick = this.handleRandomClick.bind(this)
    this.receive = this.receive.bind(this)
  }

  receive(data){
    let date = normalizeDate(new Date(data.date))
    this.setState({
      image: data.url,
      image_hd: data.hdurl,
      title: data.title,
      explanation: data.explanation,
      date: date,
      tries: 0,
      isFailure: false,
      isLoading: false
    })
  }

  makeRequest(date){
    getByDate(date)
    .then(this.receive)
    .catch(err => {
      if (this.state.tries >= Constants.MAX_TRY)  {
        this.setState({
          isFailure: true,
          isLoading: false
        })<commit_msg>Load image async<commit_after>import { h, Component } from 'preact';
import AppConstants from '../constants/AppConstants'
import Constants from '../constants/Constants'
const config = require('../../appconfig')

let getLatest, getByDate
if (config.mode === AppConstants.DEV_MODE) {
  getLatest = require('../../test/helpers/api_fixture').getLatest
  getByDate = require('../../test/helpers/api_fixture').getByDate
} else {
  getLatest = require('../helpers/api').getLatest
  getByDate = require('../helpers/api').getByDate
}

import Wrapper from '../components/Wrapper'

import yesterday from '../helpers/yesterday'
import tomorrow from '../helpers/tomorrow'
import normalizeDate from '../helpers/normalize-date'
import randomDate from '../helpers/random-date'

const downloadImage = new Image()

class App extends Component {
  constructor(props){
    super(props)
    this.state = {
      isLoading: true,
      tries: 0,
      isFailure: false,
      showInfo: true
    }

    this.handlePreviousClick = this.handlePreviousClick.bind(this)
    this.handleNextClick = this.handleNextClick.bind(this)
    this.handleToggleClick = this.handleToggleClick.bind(this)
    this.handleRandomClick = this.handleRandomClick.bind(this)
    this.receive = this.receive.bind(this)
  }

  receive(data){
    let date = normalizeDate(new Date(data.date))
    
    downloadImage.onload = () => {
      this.setState({
        image: data.url,
        image_hd: data.hdurl,
        title: data.title,
        explanation: data.explanation,
        date: date,
        tries: 0,
        isFailure: false,
        isLoading: false
      })
    }

    downloadImage.src = data.hdurl
  }

  makeRequest(date){
    getByDate(date)
    .then(this.receive)
    .catch(err => {
      if (this.state.tries >= Constants.MAX_TRY)  {
        this.setState({
          isFailure: true,
          isLoading: false
        })
{'fraction_non_alphanumeric': 0.1330777656078861, 'fraction_numerical': 0.001095290251916758, 'mean_word_length': 2.9749727965179544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5071134', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1118, 'n_words': 229}