<commit_before>import _ from 'lodash'
import React, { Component, PropTypes as Types } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import Headroom from 'react-headrooms'
import MdSearch from 'react-icons/lib/md/search'
import MdPerson from 'react-icons/lib/md/person'
import MdNotificationsNone from 'react-icons/lib/md/notifications-none'
import {
  logout
} from 'redux/actions/user'
import {
  showLoginModal
} from 'redux/actions/global'
import Dropdown from 'components/dropdown'
import styles from './index.scss'

class Header extends Component {
  constructor (props) {
    super(props)
  }
  render () {
    const showHeader = _.include(['/write'], this.props.pathname)
    const showAuthCtrl = !_.include(['/login', '/register', '/forgot'], this.props.pathname)
    const UserAction = (props) => {
      return (
        <ul className={styles.userAction}>
          <li>
            <Link to='/setting'>设置</Link>
          </li>
          <li>
            <a href='javascript:void(0)' onClick={props.logout}><MdPerson />退出</a>
          </li>
        </ul>
      )
    }
    const search = this.props.logind ? (
      <li>
        <Link to='/search'>
          <MdSearch />
        </Link>
      </li>
    ) : null
    const notification = this.props.logind ? (
      <li>
        <Link to='/notifications'>
          <MdNotificationsNone />
        </Link>
      </li>
    ) : null
    const touxiang = this.props.logind ? (
        <li>
          <Dropdown
            trigger={
              <img src={this.props.user.avatarUrl} className={styles.avatar} width='45' height='45' />
            }
            transitionName='fadeIn'
          >
            <UserAction user={this.props.user} logout={this.props.logout} />
          </Dropdown>
        </li>
    ) : showAuthCtrl && (
      <div className={styles.authAction}>
        <a href='javscript:void(0)' onClick={this.props.showLoginModal} >登录</a>
        <small> | </small>
        <Link to='/register'>注册</Link>
      </div>
    )
    const header = (
      <header className={styles.header}>
        <div className={styles.headerWarp}>
          <div className='row'>
            <div className='three columns'>
              <Link to='/' className={styles.logo}>Sley</Link>{ /* <img src='' alt='' /> */}
            </div>
            <div className='nine columns'>
              <ul className={styles.headerList}>
                {search}
                {notification}
                {touxiang}
              </ul>
            </div>
          </div>
        </div>
      </header>
    )
    console.log(this.props.pathname)
    if (showHeader) return <div />
    return (
      <Headroom tolerance={5} offset={100} classes={{
        initial: 'animated',
        pinned: 'slideInDown',
        unpinned: 'slideOutUp'
      }}>
        {header}
      </Headroom>
    )
  }
}

Header.propTypes = {
  loading: Types.bool.isRequired,
  logind: Types.bool.isRequired,
  logout: Types.func.isRequired,
  user: Types.object.isRequired,
  showLoginModal: Types.func.isRequired,
  pathname: Types.string.isRequired
}

const select = state => {
  const authState = state.get('UserStore')
  return {
    user: authState.get('user').toJS(),
    logind: authState.get('logind'),
    loading: authState.get('loading'),
    pathname: state.get('routing').locationBeforeTransitions.pathname
  }
}

const mapDispatchToProps = dispatch => {
  return {
    logout: bindActionCreators(logout, dispatch),
    showLoginModal: bindActionCreators(showLoginModal, dispatch)
  }
}

export default connect(select, mapDispatchToProps)(Header)<commit_msg>Update header<commit_after>import _ from 'lodash'
import React, { Component, PropTypes as Types } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import Headroom from 'react-headrooms'
import MdSearch from 'react-icons/lib/md/search'
import MdPerson from 'react-icons/lib/md/person'
import MdNotificationsNone from 'react-icons/lib/md/notifications-none'
import {
  logout
} from 'redux/actions/user'
import {
  showLoginModal
} from 'redux/actions/global'
import Dropdown from 'components/dropdown'
import styles from './index.scss'

const Search = (props) => {
  return props.logind && (
    <Link to='/search'>
      <MdSearch />
    </Link>
  )
}

const Notification = (props) => {
  return props.logind && (
    <Link to='/notifications'>
      <MdNotificationsNone />
    </Link>
  )
}

const Touxiang = (props) => {
  return (
    <Dropdown
      trigger={
        <img src={props.user.avatarUrl} className={styles.avatar} width='45' height='45' />
      }
      transitionName='fadeIn'
    >
      <ul className={styles.userAction}>
        <li>
          <Link to='/setting'>设置</Link>
        </li>
        <li>
          <a href='javascript:void(0)' onClick={props.logout}><MdPerson />退出</a>
        </li>
      </ul>
    </Dropdown>
  )
}

Touxiang.propTypes = {
  user: Types.object.isRequired,
  logout: Types.func.isRequired
}

class Header extends Component {
  constructor (props) {
    super(props)
  }
  render () {
    if (_.include(['/write'], this.props.pathname)) return null
    const showAuthCtrl = !_.include(['/login', '/register', '/forgot'], this.props.pathname)
    return (
      <Headroom tolerance={5} offset={100} classes={{
        initial: 'animated',
        pinned: 'slideInDown',
        unpinned: 'slideOutUp'
      }}>
        <header className={styles.header}>
          <div className={styles.headerWarp}>
            <div className='row'>
              <div className='three columns'>
                <Link to='/' className={styles.logo}>Sley</Link>{ /* <img src='' alt='' /> */}
              </div>
              <div className='nine columns'>
                <ul className={styles.headerList}>
                  <li>
                    <Search logind={this.props.logind} />
                  </li>
                  <li>
                    <Notification logind={this.props.logind} />
                  </li>
                  <li>
                    {this.props.logind ? <Touxiang user={this.props.user} logout={this.props.logout} /> : showAuthCtrl && (
                      <div className={styles.authAction}>
                        <a href='javscript:void(0)' onClick={this.props.showLoginModal} >登录</a>
                        <small> | </small>
                        <Link to='/register'>注册</Link>
                      </div>
                    )}
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </header>
      </Headroom>
    )
  }
}

Header.propTypes = {
  loading: Types.bool.isRequired,
  logind: Types.bool.isRequired,
  logout: Types.func.isRequired,
  user: Types.object.isRequired,
  showLoginModal: Types.func.isRequired,
  pathname: Types.string.isRequired
}

const select = state => {
  const authState = state.get('UserStore')
  return {
    user: authState.get('user').toJS(),
    logind: authState.get('logind'),
    loading: authState.get('loading'),
    pathname: state.get('routing').locationBeforeTransitions.pathname
  }
}

const mapDispatchToProps = {
  logout,
  showLoginModal
}

export default connect(select, mapDispatchToProps)(Header)
{'fraction_non_alphanumeric': 0.14621871599564745, 'fraction_numerical': 0.002720348204570185, 'mean_word_length': 2.243493603881782, 'pattern_counts': {'":': 0, '<': 110, '<?xml version=': 0, '>': 117, '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': '3377664', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2248, 'n_words': 453}