<commit_before>/* global cozy */
import React, { Component } from 'react'

// Extreme fallback: returns a direct download link to the raw image
const getPhotoLink = async (photoId) => {
  return await cozy.client.files.getDownloadLinkById(photoId)
    .then(path => `${cozy.client._url}${path}`)
}

export default class ImageLoader extends Component {
  state = {
    loading: true,
    fallback: null
  }

  onLoad = () => {
    this.setState({ loading: false })
    if (this.props.onLoad) this.props.onLoad()
  }

  onError = () => {
    if (!this.img) return // if we already unmounted
    if (this.state.fallback && this.img.src === this.state.fallback) return
    // extreme fallback
    getPhotoLink(this.props.photo._id)
      .then(url => {
        this.img.src = url
        this.setState({ loading: false, fallback: url })
        if (this.props.onLoad) this.props.onLoad()
      })
  }

  componentWillUnmount () {
    // this is needed because when opening 2 times in a row the same photo in the viewer,
    // the second time the onLoad is not fired... This will fire the onError (see above)
    this.img.src = ''
  }

  render () {
    const { photo, src, alt, className, style = {} } = this.props
    const { loading } = this.state
    return (
      <img
        ref={img => { this.img = img }}
        className={className}
        onLoad={this.onLoad}
        onError={this.onError}
        style={Object.assign({}, style)}
        alt={alt || photo.name}
        src={src}
      />
    )
  }
}
<commit_msg>fix: clean up unused const<commit_after>/* global cozy */
import React, { Component } from 'react'

// Extreme fallback: returns a direct download link to the raw image
const getPhotoLink = async (photoId) => {
  return await cozy.client.files.getDownloadLinkById(photoId)
    .then(path => `${cozy.client._url}${path}`)
}

export default class ImageLoader extends Component {
  state = {
    fallback: null
  }

  onLoad = () => {
    if (this.props.onLoad) this.props.onLoad()
  }

  onError = () => {
    if (!this.img) return // if we already unmounted
    if (this.state.fallback && this.img.src === this.state.fallback) return
    // extreme fallback
    getPhotoLink(this.props.photo._id)
      .then(url => {
        this.img.src = url
        this.setState({ fallback: url })
        if (this.props.onLoad) this.props.onLoad()
      })
  }

  componentWillUnmount () {
    // this is needed because when opening 2 times in a row the same photo in the viewer,
    // the second time the onLoad is not fired... This will fire the onError (see above)
    this.img.src = ''
  }

  render () {
    const { photo, src, alt, className, style = {} } = this.props
    return (
      <img
        ref={img => { this.img = img }}
        className={className}
        onLoad={this.onLoad}
        onError={this.onError}
        style={Object.assign({}, style)}
        alt={alt || photo.name}
        src={src}
      />
    )
  }
}

{'fraction_non_alphanumeric': 0.13840947546531304, 'fraction_numerical': 0.0006768189509306261, 'mean_word_length': 2.441210710128056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5913292', 'n_tokens_mistral': 934, 'n_tokens_neox': 920, 'n_words': 256}