<commit_before>import h from 'react-hyperscript'
import PropTypes from 'prop-types'
import { compose } from 'recompose'
import { connect as connectStyles } from 'react-fela'
import { isNil, not, and, either, isEmpty } from 'ramda'
import MuiAvatar from 'material-ui/Avatar'
import FontIcon from 'material-ui/FontIcon'

import styles from '../styles/ProfileIcon'

// (mw) these values are _arbitrary_!
// TODO make them more legit
const sizeInPx = {
  small: 40,
  medium: 60,
  large: 80
}

export default compose(
  connectStyles(styles)
)(Avatar)

function Avatar (props) {
  const {
    styles,
    agent,
    size,
    icon,
    dirtyAvatar = ''
  } = props

  const hasDirtyAvatar = not(isEmpty(dirtyAvatar))

  const hasIcon = not(isNil(icon))

  if (isNil(agent)) return null

  const { profile } = agent

  if (isNil(profile)) return null

  const { name, avatar } = profile

  const hasName = not(isNil(name))
  const hasAvatar = not(isNil(avatar))

  const shouldDisplayIcon = and(not(hasAvatar), not(hasDirtyAvatar), not(hasName), hasIcon)

  const src = hasDirtyAvatar ? dirtyAvatar : hasAvatar ? avatar : null

  return (
    h('div', {
      className: styles.container
    }, [
      h(MuiAvatar, {
        className: styles.avatar,
        size: sizeInPx[size],
        icon: (
          shouldDisplayIcon
            ? h(FontIcon, {
                className: `fa fa-${icon}`
              })
            : null
        ),
        src: src
      }, [
        and(not(hasAvatar), hasName)
          ? name.substring(0, 1)
          : null
      ])
    ])
  )
}

Avatar.propTypes = {
  avatar: PropTypes.string,
  size: PropTypes.oneOf(['small', 'medium', 'large'])
}

Avatar.defaultProps = {
  size: 'small'
}<commit_msg>bugfix(avatar): fixed conditions governing display of icon and of initial<commit_after>import h from 'react-hyperscript'
import PropTypes from 'prop-types'
import { compose } from 'recompose'
import { connect as connectStyles } from 'react-fela'
import { isNil, not, and, either, isEmpty, all } from 'ramda'
import MuiAvatar from 'material-ui/Avatar'
import FontIcon from 'material-ui/FontIcon'

import styles from '../styles/ProfileIcon'

// (mw) these values are _arbitrary_!
// TODO make them more legit
const sizeInPx = {
  small: 40,
  medium: 60,
  large: 80
}

export default compose(
  connectStyles(styles)
)(Avatar)

function Avatar (props) {
  const {
    styles,
    agent,
    size,
    icon,
    dirtyAvatar = ''
  } = props

  const hasDirtyAvatar = not(isEmpty(dirtyAvatar))

  const hasIcon = not(isNil(icon))

  if (isNil(agent)) return null

  const { profile } = agent

  if (isNil(profile)) return null

  const { name, avatar } = profile

  const hasName = not(isNil(name))
  const hasAvatar = not(isNil(avatar))

  const shouldDisplayIcon = and(and(not(hasAvatar), not(hasDirtyAvatar)), and(not(hasName), hasIcon))

  const src = hasDirtyAvatar ? dirtyAvatar : hasAvatar ? avatar : null

  return (
    h('div', {
      className: styles.container
    }, [
      h(MuiAvatar, {
        className: styles.avatar,
        size: sizeInPx[size],
        icon: (
          shouldDisplayIcon
            ? h(FontIcon, {
                className: `fa fa-${icon}`
              })
            : null
        ),
        src: src
      }, [
        and(and(not(hasAvatar), not(hasDirtyAvatar)), hasName)
          ? name.substring(0, 1)
          : null
      ])
    ])
  )
}

Avatar.propTypes = {
  avatar: PropTypes.string,
  size: PropTypes.oneOf(['small', 'medium', 'large'])
}

Avatar.defaultProps = {
  size: 'small'
}
{'fraction_non_alphanumeric': 0.12335664335664336, 'fraction_numerical': 0.0044755244755244755, 'mean_word_length': 2.7563025210084033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1752151', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1171, 'n_words': 299}