<commit_before>import React from "react";
import * as H from "history";
import { BrowserRouter as Router, Redirect, Route, RouteProps, Switch } from "react-router-dom";
import { ThemeProvider } from "theme-ui";

import { getJWT, jwtIsExpired } from "./jwt";
import Toast from "./components/Toast";
import ActivateAccountScreen from "./screens/ActivateAccountScreen";
import CreateProjectScreen from "./screens/CreateProjectScreen";
import ForgotPasswordScreen from "./screens/ForgotPasswordScreen";
import HomeScreen from "./screens/HomeScreen";
import LoginScreen from "./screens/LoginScreen";
import OrganizationScreen from "./screens/OrganizationScreen";
import OrganizationAdminScreen from "./screens/OrganizationAdminScreen";
import ProjectScreen from "./screens/ProjectScreen";
import RegistrationScreen from "./screens/RegistrationScreen";
import ResetPasswordScreen from "./screens/ResetPasswordScreen";
import theme from "./theme";

import "./App.css";
import StartProjectScreen from "./screens/StartProjectScreen";

const PrivateRoute = ({ children, ...props }: RouteProps) => {
  const savedJWT = getJWT();
  const notLoggedIn = !savedJWT || jwtIsExpired(savedJWT);
  return (
    <Route
      {...props}
      render={({ location }: { readonly location: H.Location }) => {
        return notLoggedIn ? (
          <Redirect to={{ pathname: "/login", state: { from: location } }} />
        ) : (
          children
        );
      }}
    />
  );
};

const AdminRoute = ({ children, ...props }: RouteProps) => {
  const savedJWT = getJWT();
  const notLoggedIn = !savedJWT || jwtIsExpired(savedJWT);
  // TODO: Implement Admin guarding. Not entirely sure how to do this - can we access redux store?
  // One possible solution: https://github.com/acdlite/redux-router/issues/60#issuecomment-141691675
  return (
    <Route
      {...props}
      render={({ location }: { readonly location: H.Location }) => {
        return notLoggedIn ? (
          <Redirect to={{ pathname: "/login", state: { from: location } }} />
        ) : (
          children
        );
      }}
    />
  );
};

const App = () => (
  <ThemeProvider theme={theme}>
    <Toast />
    <Router>
      <Switch>
        <PrivateRoute path="/" exact={true}>
          <HomeScreen />
        </PrivateRoute>
        <Route path="/o/:organizationSlug" exact={true} component={OrganizationScreen} />
        <AdminRoute path="/o/:organizationSlug/admin" exact={true}>
          <OrganizationAdminScreen></OrganizationAdminScreen>
        </AdminRoute>
        <Route path="/projects/:projectId" exact={true} component={ProjectScreen} />
        <Route path="/login" exact={true} component={LoginScreen} />
        <Route path="/register" exact={true} component={RegistrationScreen} />
        <Route path="/forgot-password" exact={true} component={ForgotPasswordScreen} />
        <Route path="/activate/:token" exact={true} component={ActivateAccountScreen} />
        <Route path="/password-reset/:token" exact={true} component={ResetPasswordScreen} />
        <PrivateRoute path="/create-project" exact={true}>
          <CreateProjectScreen />
        </PrivateRoute>
        <PrivateRoute path="/start-project" exact={true}>
          <StartProjectScreen />
        </PrivateRoute>
      </Switch>
    </Router>
  </ThemeProvider>
);

export default App;
<commit_msg>Remove unused admin route guard<commit_after>import React from "react";
import * as H from "history";
import { BrowserRouter as Router, Redirect, Route, RouteProps, Switch } from "react-router-dom";
import { ThemeProvider } from "theme-ui";

import { getJWT, jwtIsExpired } from "./jwt";
import Toast from "./components/Toast";
import ActivateAccountScreen from "./screens/ActivateAccountScreen";
import CreateProjectScreen from "./screens/CreateProjectScreen";
import ForgotPasswordScreen from "./screens/ForgotPasswordScreen";
import HomeScreen from "./screens/HomeScreen";
import LoginScreen from "./screens/LoginScreen";
import OrganizationScreen from "./screens/OrganizationScreen";
import OrganizationAdminScreen from "./screens/OrganizationAdminScreen";
import ProjectScreen from "./screens/ProjectScreen";
import RegistrationScreen from "./screens/RegistrationScreen";
import ResetPasswordScreen from "./screens/ResetPasswordScreen";
import theme from "./theme";

import "./App.css";
import StartProjectScreen from "./screens/StartProjectScreen";

const PrivateRoute = ({ children, ...props }: RouteProps) => {
  const savedJWT = getJWT();
  const notLoggedIn = !savedJWT || jwtIsExpired(savedJWT);
  return (
    <Route
      {...props}
      render={({ location }: { readonly location: H.Location }) => {
        return notLoggedIn ? (
          <Redirect to={{ pathname: "/login", state: { from: location } }} />
        ) : (
          children
        );
      }}
    />
  );
};

const App = () => (
  <ThemeProvider theme={theme}>
    <Toast />
    <Router>
      <Switch>
        <PrivateRoute path="/" exact={true}>
          <HomeScreen />
        </PrivateRoute>
        <Route path="/o/:organizationSlug" exact={true} component={OrganizationScreen} />
        <PrivateRoute path="/o/:organizationSlug/admin" exact={true}>
          <OrganizationAdminScreen/>
        </PrivateRoute>
        <Route path="/projects/:projectId" exact={true} component={ProjectScreen} />
        <Route path="/login" exact={true} component={LoginScreen} />
        <Route path="/register" exact={true} component={RegistrationScreen} />
        <Route path="/forgot-password" exact={true} component={ForgotPasswordScreen} />
        <Route path="/activate/:token" exact={true} component={ActivateAccountScreen} />
        <Route path="/password-reset/:token" exact={true} component={ResetPasswordScreen} />
        <PrivateRoute path="/create-project" exact={true}>
          <CreateProjectScreen />
        </PrivateRoute>
        <PrivateRoute path="/start-project" exact={true}>
          <StartProjectScreen />
        </PrivateRoute>
      </Switch>
    </Router>
  </ThemeProvider>
);

export default App;

{'fraction_non_alphanumeric': 0.145427533839551, 'fraction_numerical': 0.0018157807857378673, 'mean_word_length': 3.403343023255814, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 70, 'https://': 1, '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': '4967161', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1639, 'n_words': 400}