<commit_before>import React, { Component } from 'react';
import { Link } from 'react-router';
import Grid from 'react-bootstrap/lib/Grid';
import { updateLocale } from '../../actions/intlActions';
import { pushErrors } from '../../actions/errorActions';
import Navbar from './BsNavbar';
import NavLink from './NavLink';
import MenuItem from './MenuItem';
import Text from '../widgets/Text';

class Navigation extends Component {
  _setLanguage(lang) {
    let { store } = this.context;
    store
      .dispatch(updateLocale(lang))
      .then(() => {
        console.log('load locale (manually) ok');
      }, (err) => {
        store.dispatch(pushErrors(err));
      });
  }

  render() {
    let { cookies: { token, user } } = this.context.store.getState();
    let isAuth = !!token;
    user = (user && JSON.parse(user)) || {};

    return (
      <Navbar staticTop>
        <Grid>
          <Navbar.Header>
            <Link className="navbar-brand" to="/" >
              Logo
            </Link>
          </Navbar.Header>

          <Navbar.Body>
            <Navbar.Nav>
              <NavLink to="/" onlyActiveOnIndex>
                <Text id="nav.home" />
              </NavLink>
              <NavLink to="/todo">
                <Text id="nav.todo" />
              </NavLink>
              <NavLink to="/does/not/exist">
                404
              </NavLink>
            </Navbar.Nav>

            <Navbar.Nav right>
              <Navbar.Dropdown title={<Text id="nav.language" />}>
                <MenuItem
                  title="English"
                  onClick={this._setLanguage.bind(this, 'en-us')}
                />
                <MenuItem
                  title="繁體中文"
                  onClick={this._setLanguage.bind(this, 'zh-tw')}
                />
                <MenuItem
                  title="Not supported"
                  onClick={this._setLanguage.bind(this, 'foo-bar')}
                />
              </Navbar.Dropdown>
              <Navbar.Dropdown
                title={
                  !isAuth ?
                  <Text id="nav.user" /> :
                  (user.name || user.email)}
              >
                {!isAuth &&
                  <NavLink to="/user/login">
                    <Text id="nav.user.login" />
                  </NavLink>}
                {!isAuth &&
                  <NavLink to="/user/register">
                    <Text id="nav.user.register" />
                  </NavLink>}
                {isAuth &&
                  <NavLink to="/user/me">
                    <Text id="nav.user.profile" />
                  </NavLink>}
                {isAuth &&
                  <NavLink to="/user/logout">
                    <Text id="nav.user.logout" />
                  </NavLink>}
              </Navbar.Dropdown>
            </Navbar.Nav>
          </Navbar.Body>
        </Grid>
      </Navbar>
    );
  }
};<commit_msg>Update component Navigation<commit_after>import React, { Component } from 'react';
import { Link } from 'react-router';
import Grid from 'react-bootstrap/lib/Grid';
import Roles from '../../constants/Roles';
import { updateLocale } from '../../actions/intlActions';
import { pushErrors } from '../../actions/errorActions';
import Navbar from './BsNavbar';
import NavLink from './NavLink';
import MenuItem from './MenuItem';
import Text from '../widgets/Text';

class Navigation extends Component {
  _setLanguage(lang) {
    let { store } = this.context;
    store
      .dispatch(updateLocale(lang))
      .then(() => {
        console.log('load locale (manually) ok');
      }, (err) => {
        store.dispatch(pushErrors(err));
      });
  }

  render() {
    let { cookies: { token, user } } = this.context.store.getState();
    let isAuth = !!token;
    user = (user && JSON.parse(user)) || {};
    let isAdmin = (user.role === Roles.ADMIN);

    return (
      <Navbar staticTop>
        <Grid>
          <Navbar.Header>
            <Link className="navbar-brand" to="/" >
              Logo
            </Link>
          </Navbar.Header>

          <Navbar.Body>
            <Navbar.Nav>
              <NavLink to="/" onlyActiveOnIndex>
                <Text id="nav.home" />
              </NavLink>
              <NavLink to="/todo">
                <Text id="nav.todo" />
              </NavLink>
              <NavLink to="/does/not/exist">
                404
              </NavLink>
            </Navbar.Nav>

            <Navbar.Nav right>
              <Navbar.Dropdown title={<Text id="nav.language" />}>
                <MenuItem
                  title="English"
                  onClick={this._setLanguage.bind(this, 'en-us')}
                />
                <MenuItem
                  title="繁體中文"
                  onClick={this._setLanguage.bind(this, 'zh-tw')}
                />
                <MenuItem
                  title="Not supported"
                  onClick={this._setLanguage.bind(this, 'foo-bar')}
                />
              </Navbar.Dropdown>
              <Navbar.Dropdown
                title={
                  !isAuth ?
                  <Text id="nav.user" /> :
                  (user.name || user.email)}
              >
                {!isAuth &&
                  <NavLink to="/user/login">
                    <Text id="nav.user.login" />
                  </NavLink>}
                {!isAuth &&
                  <NavLink to="/user/register">
                    <Text id="nav.user.register" />
                  </NavLink>}
                {isAuth && isAdmin &&
                  <NavLink to="/admin">
                    Admin System
                  </NavLink>}
                {isAuth &&
                  <NavLink to="/user/me">
                    <Text id="nav.user.profile" />
                  </NavLink>}
                {isAuth &&
                  <NavLink to="/user/logout">
                    <Text id="nav.user.logout" />
                  </NavLink>}
              </Navbar.Dropdown>
            </Navbar.Nav>
          </Navbar.Body>
        </Grid>
      </Navbar>
    );
  }
};
{'fraction_non_alphanumeric': 0.14687037949728932, 'fraction_numerical': 0.0009857072449482504, 'mean_word_length': 1.2194677360554138, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 95, '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': '964705', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1637, 'n_words': 317}