<commit_before>import React from "react";
import { Link, withRouter } from "react-router-dom";
import { NavBar } from "simple-react-bootstrap";
import { connect } from "react-redux";
import cn from "classnames";

const ToucanLogo = require("../assets/toucan_logo.png");

const Nav = ({ location, current_user }) => {
  const user = current_user.user || {};
  let active =
    (location.pathname.split("/")[1] === "orgs" && "orgs") || "needs";

  const links = current_user.links || [];
  const keyed_links = links.reduce(
    (prev, link) => ({ ...prev, [link.key]: link }),
    {}
  );
  // the actual links
  const settings_link = keyed_links.settings;
  const logout_link = keyed_links.logout;
  const support_link = keyed_links.support;

  return (
    <NavBar>
      <NavBar.Header>
        <NavBar.Brand>
          <Link to="/">
            <img
              alt="Toucan Logo"
              className="navbar-logo img-responsive"
              src={ToucanLogo}
            />
          </Link>
        </NavBar.Brand>
        <NavBar.Toggle />
      </NavBar.Header>

      <NavBar.Nav className="navbar-main">
        <li className={cn("nav-issues", { active: active === "needs" })}>
          <Link to="/">Needs</Link>
        </li>
        <li className={cn("nav-orgs", { active: active === "orgs" })}>
          <Link to="/orgs/">Organisations</Link>
        </li>
        {/* this one comes from the server and might not be available at first render*/}
        {settings_link ? (
          <li className="nav-settings">
            <a href={settings_link.url}>Profile and Settings</a>
          </li>
        ) : null}
      </NavBar.Nav>
      <NavBar.Nav className="navbar-secondary navbar-right">
        {support_link ? (
          <NavBar.Item
            className="nav-muted"
            key={support_link.url}
            href={support_link.url}
          >
            <span className="icon icon-support icon-lg" />
            Support
          </NavBar.Item>
        ) : null}
        {logout_link ? (
          <NavBar.Item
            className="nav-muted"
            key={logout_link.url}
            href={logout_link.url}
          >
            <span className="icon icon-logout icon-lg" />
            Logout
          </NavBar.Item>
        ) : null}
      </NavBar.Nav>
    </NavBar>
  );
};

const ToucanNav = connect((state, { location }) => {
  return {
    location,
    current_user: state.currentUser
  };
})(Nav);

export default withRouter(ToucanNav);<commit_msg>pure css nav<commit_after>import React from "react";
import { Link, withRouter } from "react-router-dom";
import { connect } from "react-redux";
import cn from "classnames";

const ToucanLogo = require("../assets/toucan_logo.png");

class NavBar extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      open: false
    };
    this.toggle = this.toggle.bind(this);
  }

  toggle() {
    this.setState(state => ({ open: !state.open }));
  }

  render() {
    const { location, current_user } = this.props;
    let active =
      (location.pathname.split("/")[1] === "orgs" && "orgs") || "needs";

    const links = current_user.links || [];

    const keyed_links = links.reduce(
      (prev, link) => ({ ...prev, [link.key]: link }),
      {}
    );
    // the actual links
    const settings_link = keyed_links.settings;
    const logout_link = keyed_links.logout;
    const support_link = keyed_links.support;

    return (
      <nav className="navbar navbar-default">
        <div className="container-fluid">
          <div className="navbar-header">
            <button
              type="button"
              onClick={this.toggle}
              className={cn("navbar-toggle", { collapsed: this.state.open })}
            >
              <span className="sr-only">Toggle navigation</span>
              <span className="icon-bar" />
              <span className="icon-bar" />
              <span className="icon-bar" />
            </button>
            <Link to="/" className="navbar-brand">
              <img
                alt="Toucan Logo"
                className="navbar-logo img-responsive"
                src={ToucanLogo}
              />
            </Link>
          </div>
          <div
            className={cn("collapse navbar-collapse", { in: this.state.open })}
            onClick={this.toggle}
          >
            <ul className="nav navbar-nav navbar-main">
              <li className={cn("nav-issues", { active: active === "needs" })}>
                <Link to="/">Needs</Link>
              </li>
              <li className={cn("nav-orgs", { active: active === "orgs" })}>
                <Link to="/orgs/">Organisations</Link>
              </li>
              {/* this one comes from the server and might not be available at first render*/}
              {settings_link ? (
                <li className="nav-settings">
                  <a href={settings_link.url}>Profile and Settings</a>
                </li>
              ) : null}
            </ul>
            <ul className="nav navbar-nav navbar-right navbar-secondary">
              {support_link ? (
                <li className="nav-muted">
                  <a key={support_link.url} href={support_link.url}>
                    <span className="icon icon-support icon-lg" />
                    Support
                  </a>
                </li>
              ) : null}
              {logout_link ? (
                <li className="nav-muted" key={logout_link.url}>
                  <a href={logout_link.url}>
                    <span className="icon icon-logout icon-lg" />
                    Logout
                  </a>
                </li>
              ) : null}
            </ul>
          </div>
        </div>
      </nav>
    );
  }
}

const ToucanNav = connect((state, { location }) => {
  return {
    location,
    current_user: state.currentUser
  };
})(NavBar);

export default withRouter(ToucanNav);
{'fraction_non_alphanumeric': 0.14783774723432785, 'fraction_numerical': 0.00033523298692591353, 'mean_word_length': 1.743448275862069, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 85, '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': '5279302', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1716, 'n_words': 363}