<commit_before>import React, { PropTypes } from 'react'
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
import { Link } from 'react-router'
import { push } from 'react-router-redux'
import { injectIntl, intlShape, defineMessages, FormattedMessage } from 'react-intl'
import MediaQuery from 'react-responsive'

class SearchHeader extends React.Component {
  constructor (props) {
    super(props)
    this.handleSearch = this.handleSearch.bind(this)
    this.handleLoginClick = this.handleLoginClick.bind(this)
    this.toggleMobileNav = this.toggleMobileNav.bind(this)
    this.handleRegistrationClick = this.handleRegistrationClick.bind(this)
    this.state = {
      mobileNavVisible: false
    }
  }

  componentDidUpdate () {
    this.searchFieldInput.value = this.props.locationQuery.query || ''
  }

  handleSearch (event) {
    event.preventDefault()
    this.setState({mobileNavVisible: false})
    this.props.dispatch(push({ pathname: '/search', query: { query: this.searchFieldInput.value } }))
  }

  handleLoginClick (event) {
    event.preventDefault()
    this.setState({mobileNavVisible: false})
    this.props.showLoginDialog(push({ pathname: '/profile/loans' }))
  }

  handleRegistrationClick (event) {
    event.preventDefault()
    this.props.startRegistration()
  }

  toggleMobileNav () {
    if (!this.state.mobileNavVisible) {
      this.setState({mobileNavVisible: true})
    } else {
      this.setState({mobileNavVisible: false})
    }
  }

  /**
   * Links used in the menu and the mobile menu
   */
  loginLink () {
    if (!this.props.isLoggedIn) {
      return [
        <li key={2} data-automation-id="login_element" onClick={this.handleLoginClick}>
          <Link to="/">
            <FormattedMessage {...messages.logIn} /> <span>&raquo;</span>
          </Link>
        </li>
      ]
    }
  }

  logoutLink () {
    if (this.props.isLoggedIn) {
      return [
        <li key={1} data-automation-id="logout_element" onClick={this.props.logout}>
          <Link to="/">
            <FormattedMessage {...messages.logout} /> <span>&raquo;</span>
          </Link>
        </li>
      ]
    }
  }

  profileLink () {
    if (this.props.isLoggedIn) {
      return [
        <li key={3}>
          <Link to="/profile/loans"><FormattedMessage {...messages.myProfile} /> <span>&raquo;</span></Link>
        </li>
      ]
    }
  }

  registrationLink () {
    if (!this.props.isLoggedIn) {
      return (
        <li>
          <a onClick={this.handleRegistrationClick} title="register"><FormattedMessage {...messages.register} /><span>&raquo;</span></a>
        </li>
      )
    }
  }

  /**
   * Renders the menu, and/or the mobile menu
   */
  renderNavigationLinks () {
    return (
      <ul>
        {this.profileLink()}
        {this.registrationLink()}
        {this.loginLink()}
        {this.logoutLink()}
      </ul>
    )
  }

  renderMobileNavigationLinks () {
    return (
      <ul>
        {this.profileLink()}
        {this.registrationLink()}
        {this.loginLink()}
        {this.logoutLink()}
      </ul>
    )
  }

  render () {
    const mobileNavClass = this.state.mobileNavVisible ? 'primary-mobile-menu' : 'primary-mobile-menu collapsed'
    return (
      <div>
          <ReactCSSTransitionGroup
            transitionName="fade-in"
            transitionAppear
            transitionAppearTimeout={500}
            transitionEnterTimeout={500}
            transitionLeaveTimeout={500}
            component="header"
            className="wrapper">

            <div className="logo">
              <Link to="/">
                <img src="/images/logo.png" alt={this.props.intl.formatMessage(messages.logoAlt)} />
              </Link>
            </div>

            <MediaQuery query="(max-width: 667px)" values={{ ...this.props.mediaQueryValues }}>
              <div className="mobile-menu-toggle">
                <img className="btn-mobile-toggle" src="/images/btn-mobile.svg" alt="3 black bars" onClick={this.toggleMobileNav} />
              </div>
            </MediaQuery>

            <MediaQuery query="(min-width: 668px)" values={{ ...this.props.mediaQueryValues }}>
              <nav className="primary-menu">
                {this.renderNavigationLinks()}
              </nav>
            </MediaQuery>

          </ReactCSSTransitionGroup>

        <MediaQuery query="(max-width: 667px)" values={{ ...this.props.mediaQueryValues }}><commit_msg>patron-client: Deichman logo links to https://deichman.no<commit_after>import React, { PropTypes } from 'react'
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
import { Link } from 'react-router'
import { push } from 'react-router-redux'
import { injectIntl, intlShape, defineMessages, FormattedMessage } from 'react-intl'
import MediaQuery from 'react-responsive'

class SearchHeader extends React.Component {
  constructor (props) {
    super(props)
    this.handleSearch = this.handleSearch.bind(this)
    this.handleLoginClick = this.handleLoginClick.bind(this)
    this.toggleMobileNav = this.toggleMobileNav.bind(this)
    this.handleRegistrationClick = this.handleRegistrationClick.bind(this)
    this.state = {
      mobileNavVisible: false
    }
  }

  componentDidUpdate () {
    this.searchFieldInput.value = this.props.locationQuery.query || ''
  }

  handleSearch (event) {
    event.preventDefault()
    this.setState({mobileNavVisible: false})
    this.props.dispatch(push({ pathname: '/search', query: { query: this.searchFieldInput.value } }))
  }

  handleLoginClick (event) {
    event.preventDefault()
    this.setState({mobileNavVisible: false})
    this.props.showLoginDialog(push({ pathname: '/profile/loans' }))
  }

  handleRegistrationClick (event) {
    event.preventDefault()
    this.props.startRegistration()
  }

  toggleMobileNav () {
    if (!this.state.mobileNavVisible) {
      this.setState({mobileNavVisible: true})
    } else {
      this.setState({mobileNavVisible: false})
    }
  }

  /**
   * Links used in the menu and the mobile menu
   */
  loginLink () {
    if (!this.props.isLoggedIn) {
      return [
        <li key={2} data-automation-id="login_element" onClick={this.handleLoginClick}>
          <Link to="/">
            <FormattedMessage {...messages.logIn} /> <span>&raquo;</span>
          </Link>
        </li>
      ]
    }
  }

  logoutLink () {
    if (this.props.isLoggedIn) {
      return [
        <li key={1} data-automation-id="logout_element" onClick={this.props.logout}>
          <Link to="/">
            <FormattedMessage {...messages.logout} /> <span>&raquo;</span>
          </Link>
        </li>
      ]
    }
  }

  profileLink () {
    if (this.props.isLoggedIn) {
      return [
        <li key={3}>
          <Link to="/profile/loans"><FormattedMessage {...messages.myProfile} /> <span>&raquo;</span></Link>
        </li>
      ]
    }
  }

  registrationLink () {
    if (!this.props.isLoggedIn) {
      return (
        <li>
          <a onClick={this.handleRegistrationClick} title="register"><FormattedMessage {...messages.register} /><span>&raquo;</span></a>
        </li>
      )
    }
  }

  /**
   * Renders the menu, and/or the mobile menu
   */
  renderNavigationLinks () {
    return (
      <ul>
        {this.profileLink()}
        {this.registrationLink()}
        {this.loginLink()}
        {this.logoutLink()}
      </ul>
    )
  }

  renderMobileNavigationLinks () {
    return (
      <ul>
        {this.profileLink()}
        {this.registrationLink()}
        {this.loginLink()}
        {this.logoutLink()}
      </ul>
    )
  }

  render () {
    const mobileNavClass = this.state.mobileNavVisible ? 'primary-mobile-menu' : 'primary-mobile-menu collapsed'
    return (
      <div>
          <ReactCSSTransitionGroup
            transitionName="fade-in"
            transitionAppear
            transitionAppearTimeout={500}
            transitionEnterTimeout={500}
            transitionLeaveTimeout={500}
            component="header"
            className="wrapper">

            <div className="logo">
              <a href="https://www.deichman.no/">
                <img src="/images/logo.png" alt={this.props.intl.formatMessage(messages.logoAlt)} />
              </a>
            </div>

            <MediaQuery query="(max-width: 667px)" values={{ ...this.props.mediaQueryValues }}>
              <div className="mobile-menu-toggle">
                <img className="btn-mobile-toggle" src="/images/btn-mobile.svg" alt="3 black bars" onClick={this.toggleMobileNav} />
              </div>
            </MediaQuery>

            <MediaQuery query="(min-width: 668px)" values={{ ...this.props.mediaQueryValues }}>
              <nav className="primary-menu">
                {this.renderNavigationLinks()}
              </nav>
            </MediaQuery>

          </ReactCSSTransitionGroup>

        <MediaQuery query="(max-width: 667px)" values={{ ...this.props.mediaQueryValues }}>
{'fraction_non_alphanumeric': 0.1454728145584459, 'fraction_numerical': 0.004912359048788657, 'mean_word_length': 2.3550561797752807, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '978774', 'n_tokens_mistral': 2711, 'n_tokens_neox': 2657, 'n_words': 449}