{"size": 1387, "ext": "js", "max_stars_repo_path": "src/Components/Notifier/Notifier.js", "max_stars_repo_name": "weblabhq/headquarter", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Components/Notifier/Notifier.js", "max_issues_repo_name": "weblabhq/headquarter", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Components/Notifier/Notifier.js", "max_forks_repo_name": "weblabhq/headquarter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.671875, "max_line_length": 91, "alphanum_fraction": 0.601297765}
import React, { Component } from 'react'
import { connect } from 'react-redux'
import cx from 'classnames'

import './Notifier.css'

import { close } from '../../Actions/notifications.actions'

class Notifier extends Component {
  constructor (props) {
    super(props)
    this.state = {
      timers: {}
    }
  }

  componentWillReceiveProps (nextProps) {
    // Timers
    nextProps.notifications.forEach((err) => {
      const timers = this.state.timers

      if (!timers[err.id]) {
        timers[err.id] = setTimeout(() => { this.props.close(err.id) }, this.props.timeout)
        this.setState({ timers })
      }
    })
  }

  render () {
    const { close, notifications } = this.props

    const $notifications = notifications.map(n => (
      <div className={cx('Notifier-notification', n.level)} key={n.id}>
        <div className="message">{n.message}</div>

        <a className="Notifier-close" onClick={() => close(n.id)}>
          <i className="fa fa-times" aria-hidden="true" />
        </a>
      </div>
    ))

    return (
      <div className="Notifier">
        <div className="Notifier-center">{$notifications}</div>
      </div>
    )
  }
}

Notifier.defaultProps = {
  timeout: 50000
}

const mapStateToProps = (state, props) => {
  return {
    notifications: state.notifications
  }
}

export default connect(
  mapStateToProps, {
    close
  }
)(Notifier)