<commit_before>import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom';
import { connect } from 'react-redux';
import { Spinner } from '@blueprintjs/core';

import { fetchMetadata } from 'src/actions';
import { selectSession, selectMetadata } from 'src/selectors';
import NotFoundScreen from 'src/screens/NotFoundScreen/NotFoundScreen';
import OAuthScreen from "src/screens/OAuthScreen/OAuthScreen";
import LogoutScreen from 'src/screens/LogoutScreen/LogoutScreen';
import ActivateScreen from 'src/screens/ActivateScreen/ActivateScreen';
import HomeScreen from 'src/screens/HomeScreen/HomeScreen';
import SearchScreen from 'src/screens/SearchScreen/SearchScreen';
import NotificationsScreen from 'src/screens/NotificationsScreen/NotificationsScreen';
import SourcesIndexScreen from 'src/screens/SourcesIndexScreen/SourcesIndexScreen';
import CasesIndexScreen from 'src/screens/CasesIndexScreen/CasesIndexScreen';
// import CaseScreen from 'src/screens/CaseScreen/CaseScreen';
import CollectionScreen from 'src/screens/CollectionScreen/CollectionScreen';
import CollectionDocumentsScreen from 'src/screens/CollectionDocumentsScreen/CollectionDocumentsScreen';
import CollectionXrefMatchesScreen from 'src/screens/CollectionXrefMatchesScreen/CollectionXrefMatchesScreen';
import EntityScreen from 'src/screens/EntityScreen/EntityScreen';
import DocumentScreen from 'src/screens/DocumentScreen/DocumentScreen';
import DocumentRedirectScreen from 'src/screens/DocumentRedirectScreen/DocumentRedirectScreen';

import './Router.css';


class Router extends Component {

  componentWillMount() {
    const { metadata } = this.props;
    if (!metadata.app) {
      this.props.fetchMetadata();
    }
  }

  render() {
    const { metadata, session } = this.props;
    const isLoaded = metadata && metadata.app && session;

    if (!isLoaded) {
      return (
        <div className="RouterLoading">
          <div className="spinner"><Spinner className="bp3-large"/></div>
        </div>
      )
    }

    return (
      <Switch>
        <Route path="/oauth" exact component={OAuthScreen}/>
        <Route path="/logout" exact component={LogoutScreen}/>
        <Route path="/activate/:code" exact component={ActivateScreen}/>
        <Route path="/entities/:entityId" exact component={EntityScreen}/>
        <Route path="/documents/:documentId" exact component={DocumentScreen}/>
        <Route path="/text/:documentId" exact component={DocumentRedirectScreen}/>
        <Route path="/tabular/:documentId/:sheet" exact component={DocumentRedirectScreen}/>
        <Route path="/sources" exact component={SourcesIndexScreen}/>
        <Route path="/cases" exact component={CasesIndexScreen}/>
        {/*<Route path="/cases/:collectionId" exact component={CaseScreen}/>*/}
        <Route path="/collections/:collectionId/documents" exact component={CollectionDocumentsScreen}/>
        <Route path="/collections/:collectionId" exact component={CollectionScreen}/>
        <Route path="/collections/:collectionId/xref/:otherId" exact component={CollectionXrefMatchesScreen}/>
        <Route path="/search" exact component={SearchScreen}/>
        <Route path="/notifications" exact component={NotificationsScreen}/>
        <Route path="/" exact component={HomeScreen}/>
        <Route component={NotFoundScreen}/>
      </Switch>
    );
  }
}

const mapStateToProps = (state) => {
  return {
    metadata: selectMetadata(state),
    session: selectSession(state)
  };
};

Router = connect(mapStateToProps, { fetchMetadata })(Router);
export default Router;
<commit_msg>All routes/screens are lazy loaded as seperate chunk<commit_after>import React, { Component, Suspense, lazy } from 'react';
import { Route, Switch } from 'react-router-dom';
import { connect } from 'react-redux';
import { Spinner } from '@blueprintjs/core';

import { fetchMetadata } from 'src/actions';
import { selectSession, selectMetadata } from 'src/selectors';
import './Router.scss';


const  NotFoundScreen = lazy(()=> import('src/screens/NotFoundScreen/NotFoundScreen'));
const OAuthScreen = lazy(()=> import("src/screens/OAuthScreen/OAuthScreen"));
const LogoutScreen  = lazy(()=> import('src/screens/LogoutScreen/LogoutScreen'));
const ActivateScreen = lazy(() => import('src/screens/ActivateScreen/ActivateScreen'));
const HomeScreen = lazy(()=> import('src/screens/HomeScreen/HomeScreen'));
const SearchScreen = lazy(()=> import('src/screens/SearchScreen/SearchScreen'));
const NotificationsScreen  = lazy(()=> import('src/screens/NotificationsScreen/NotificationsScreen'));
const SourcesIndexScreen  = lazy(()=> import('src/screens/SourcesIndexScreen/SourcesIndexScreen'));
const CasesIndexScreen  = lazy(()=> import('src/screens/CasesIndexScreen/CasesIndexScreen'));
// import CaseScreen from 'src/screens/CaseScreen/CaseScreen';
const CollectionScreen  = lazy(()=> import('src/screens/CollectionScreen/CollectionScreen'));
const CollectionDocumentsScreen  = lazy(()=> import('src/screens/CollectionDocumentsScreen/CollectionDocumentsScreen'));
const CollectionXrefMatchesScreen  = lazy(()=> import('src/screens/CollectionXrefMatchesScreen/CollectionXrefMatchesScreen'));
const EntityScreen  = lazy(()=> import('src/screens/EntityScreen/EntityScreen'));
const DocumentScreen  = lazy(()=> import('src/screens/DocumentScreen/DocumentScreen'));
const  DocumentRedirectScreen  = lazy(()=> import('src/screens/DocumentRedirectScreen/DocumentRedirectScreen'));



class Router extends Component {

  componentWillMount() {
    const { metadata } = this.props;
    if (!metadata.app) {
      this.props.fetchMetadata();
    }
  }

  render() {
    const { metadata, session } = this.props;
    const isLoaded = metadata && metadata.app && session;

    const Loading = (
      <div className="RouterLoading">
        <div className="spinner"><Spinner className="bp3-large"/></div>
      </div>
    );
    if (!isLoaded) {
      return Loading;
    }

    return (
      <Suspense fallback={Loading}>
        <Switch>
          <Route path="/oauth" exact component={OAuthScreen}/>
          <Route path="/logout" exact component={LogoutScreen}/>
          <Route path="/activate/:code" exact component={ActivateScreen}/>
          <Route path="/entities/:entityId" exact component={EntityScreen}/>
          <Route path="/documents/:documentId" exact component={DocumentScreen}/>
          <Route path="/text/:documentId" exact component={DocumentRedirectScreen}/>
          <Route path="/tabular/:documentId/:sheet" exact component={DocumentRedirectScreen}/>
          <Route path="/sources" exact component={SourcesIndexScreen}/>
          <Route path="/cases" exact component={CasesIndexScreen}/>
          {/*<Route path="/cases/:collectionId" exact component={CaseScreen}/>*/}
          <Route path="/collections/:collectionId/documents" exact component={CollectionDocumentsScreen}/>
          <Route path="/collections/:collectionId" exact component={CollectionScreen}/>
          <Route path="/collections/:collectionId/xref/:otherId" exact component={CollectionXrefMatchesScreen}/>
          <Route path="/search" exact component={SearchScreen}/>
          <Route path="/notifications" exact component={NotificationsScreen}/>
          <Route path="/" exact component={HomeScreen}/>
          <Route component={NotFoundScreen}/>
        </Switch>
      </Suspense>
    );
  }
}

const mapStateToProps = (state) => {
  return {
    metadata: selectMetadata(state),
    session: selectSession(state)
  };
};

Router = connect(mapStateToProps, { fetchMetadata })(Router);
export default Router;

{'fraction_non_alphanumeric': 0.13742766964755393, 'fraction_numerical': 0.0002630194634402946, 'mean_word_length': 4.637509266123054, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 70, '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': '4587770', 'n_tokens_mistral': 2027, 'n_tokens_neox': 2018, 'n_words': 429}