import React, {Component} from 'react'
import { browserHistory } from 'react-router'

/**
 * Component, for displaying ethical ad from CodeFund.
 */
class CodeFundWidget extends Component {
  componentDidMount() {
    this.unlisten = browserHistory.listen((location) => {
      if (location.action == "PUSH") {
        document.getElementById("codefund_ad").innerHTML = "";
        window._codefund.serve();
      }
    });
  }

  componentWillUnmount() {
    this.unlisten();
  }

  render() {
    return (
      <div ref="codefund" id="codefund_ad" />
    );
  }
}

export default CodeFundWidget

/*
 * Ethical ad from CodeFund.
 */

import React, {Component} from 'react'
import {browserHistory} from 'react-router'
import injectSheet from 'react-jss'

const styles = {
  container: {
    minHeight: 145
  }
}

class CodeFundWidget extends Component {
  static propTypes = {
    classes: React.PropTypes.object
  }

  componentDidMount() {
    this.unlisten = browserHistory.listen((location) => {
      if (location.action === 'PUSH') {
        this.node.innerHTML = ''
        // eslint-disable-next-line no-underscore-dangle
        window._codefund.serve()
      }
    })
  }

  componentWillUnmount() {
    this.unlisten()
  }

  onRef = (node) => {
    this.node = node
  }

  render() {
    const {classes} = this.props
    return <div ref={this.onRef} id="codefund_ad" className={classes.container} />
  }
}

export default injectSheet(styles)(CodeFundWidget)

set minHeight, lint, cleanup