<commit_before>import axios from 'axios';
import React from 'react';
import InternalNav from 'react-internal-nav';
import Home from './home/Home.jsx';
import Book from './books/Book.jsx';
import Login from './login/Login.jsx';
import Register from './register/Register.jsx';
import Search from './search/Search.jsx';
import NProgress from 'nprogress';
import localStore from 'store';

class App extends React.Component {
  componentWillMount () {
    const { store } = this.props;
    window.addEventListener('popstate', () => {
      store.dispatch({type: 'URL', pathname: window.location.pathname});
    });
    store.subscribe(() => {
      if (store.getState().routing.get('LASTACTION') === 'URL') {
        NProgress.start();
        this.forceUpdate();
      }
    });

    let loggedin = localStore.get('loggedin');
    if (typeof loggedin === 'undefined') {
      this.setState({ loggedin: 'unsure' });
      axios.get('/user').then(function (response) {
        localStore.set('loggedin', response.data);
        this.setState({ loggedin: response.data });
      }.bind(this));
    } else {
      this.setState({ loggedin });
    }

    // running it once on load
    store.dispatch({type: 'URL', pathname: window.location.pathname});
  }
  onInternalNav (pathname) {
    if (pathname === '/logout') {
      return;
    }
    if (pathname !== window.location.pathname) {
      window.history.pushState({}, '', pathname);
    }
    const { store } = this.props;
    store.dispatch({type: 'URL', pathname: window.location.pathname});
  }
  render () {
    if (this.state.loggedin === 'unsure') {
      return <div></div>
    }
    let done = () => NProgress.done();
    const { store } = this.props;
    const curPath = store.getState().routing.get('URL');
    if (curPath === '/') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
      	<Home store={store} done={done} loggedin={this.state.loggedin} />
      </InternalNav>;
    } else if (curPath.startsWith('/books/')) {
      const id = window.location.pathname.split('/').pop();
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Book store={store} id={id} done={done} loggedin={this.state.loggedin} />
       </InternalNav>
    } else if (curPath === '/search') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Search store={store} done={done} />
       </InternalNav>
    } else if (curPath.startsWith('/search/')) {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Search store={store} done={done} />
      </InternalNav>
    } else if (curPath === '/login') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Login store={store} done={done} />
      </InternalNav>
    } else if (curPath === '/register') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Register store={store} done={done} />
      </InternalNav>
    } else { // Should probably 404
      return <div>404</div>
    }
  }
}

export default App;<commit_msg>Fix loading bar when clicking on link to current page<commit_after>import axios from 'axios';
import React from 'react';
import InternalNav from 'react-internal-nav';
import Home from './home/Home.jsx';
import Book from './books/Book.jsx';
import List from './list/List.jsx';
import Login from './login/Login.jsx';
import Register from './register/Register.jsx';
import Search from './search/Search.jsx';
import NProgress from 'nprogress';
import localStore from 'store';

class App extends React.Component {
  componentWillMount () {
    const { store } = this.props;
    window.addEventListener('popstate', () => {
      store.dispatch({type: 'URL', pathname: window.location.pathname});
    });
    store.subscribe(() => {
      let state = store.getState();
      if (state.routing.get('LASTACTION') === 'URL') {
        NProgress.start();
        this.forceUpdate();
      }
      if (state.routing.get('URL') === window.location.pathname) {
        NProgress.done();
      }
    });

    let loggedin = localStore.get('loggedin');
    if (typeof loggedin === 'undefined') {
      this.setState({ loggedin: 'unsure' });
      axios.get('/user').then(function (response) {
        localStore.set('loggedin', response.data);
        this.setState({ loggedin: response.data });
      }.bind(this));
    } else {
      this.setState({ loggedin });
    }

    // running it once on load
    store.dispatch({type: 'URL', pathname: window.location.pathname});
  }
  onInternalNav (pathname) {
    if (pathname === '/logout') {
      return;
    }
    if (pathname !== window.location.pathname) {
      window.history.pushState({}, '', pathname);
    }
    const { store } = this.props;
    store.dispatch({type: 'URL', pathname: window.location.pathname});
  }
  render () {
    if (this.state.loggedin === 'unsure') {
      return <div></div>
    }
    let done = () => NProgress.done();
    const { store } = this.props;
    const curPath = store.getState().routing.get('URL');
    if (curPath === '/') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
      	<Home store={store} done={done} loggedin={this.state.loggedin} />
      </InternalNav>;
    } else if (curPath.startsWith('/books/')) {
      const id = window.location.pathname.split('/').pop();
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Book store={store} id={id} done={done} loggedin={this.state.loggedin} />
       </InternalNav>
    } else if (curPath === '/search') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Search store={store} done={done} />
       </InternalNav>
    } else if (curPath.startsWith('/search/')) {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Search store={store} done={done} />
      </InternalNav>
    } else if (curPath === '/login') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Login store={store} done={done} />
      </InternalNav>
    } else if (curPath === '/register') {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <Register store={store} done={done} />
      </InternalNav>
    } else if (curPath.startsWith('/list')) {
      return <InternalNav onInternalNav={this.onInternalNav.bind(this)}>
        <List store={store} done={done} />
      </InternalNav>
    } else { // Should probably 404
      return <h1>404</h1>
    }
  }
}

export default App;
{'fraction_non_alphanumeric': 0.171939477303989, 'fraction_numerical': 0.0021396912731163073, 'mean_word_length': 3.067122436295836, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 56, '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': '2835794', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1995, 'n_words': 427}