beddbf9c0b
* tslint cleanup * app crash page improvements * fix long lines * remove unused auth code * add more tests * add tslint to scripts and fix deprecations
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import "./css/_index.scss";
|
|
import * as React from "react";
|
|
import { Provider } from "react-redux";
|
|
import { Router } from "react-router";
|
|
import { store as _store } from "./redux/store";
|
|
import { history } from "./history";
|
|
import { Store } from "./redux/interfaces";
|
|
import { ready } from "./config/actions";
|
|
import { Session } from "./session";
|
|
import { attachToRoot } from "./util";
|
|
import { Callback } from "i18next";
|
|
import { topLevelRoutes } from "./route_config";
|
|
import { ErrorBoundary } from "./error_boundary";
|
|
|
|
interface RootComponentProps { store: Store; }
|
|
|
|
export const attachAppToDom: Callback = () => {
|
|
attachToRoot(RootComponent, { store: _store });
|
|
// tslint:disable-next-line:no-any
|
|
_store.dispatch(ready() as any);
|
|
};
|
|
|
|
export class RootComponent extends React.Component<RootComponentProps, {}> {
|
|
componentWillMount() {
|
|
const notLoggedIn = !Session.fetchStoredToken();
|
|
const currentLocation = history.getCurrentLocation().pathname;
|
|
const restrictedArea = currentLocation.includes("/app");
|
|
(notLoggedIn && restrictedArea && Session.clear());
|
|
}
|
|
|
|
render() {
|
|
return <ErrorBoundary>
|
|
<Provider store={_store}>
|
|
<Router history={history}>
|
|
{topLevelRoutes}
|
|
</Router>
|
|
</Provider>
|
|
</ErrorBoundary>;
|
|
}
|
|
}
|