2019-12-10 09:47:32 +02:00
|
|
|
import React from 'react';
|
2020-10-23 01:23:59 +03:00
|
|
|
import { Route, Switch } from 'react-router-dom';
|
2019-12-07 21:43:08 +02:00
|
|
|
import clsx from 'clsx';
|
2020-07-22 13:01:12 +03:00
|
|
|
|
|
|
|
import { connect } from 'app/functions';
|
|
|
|
import { resetAuth } from 'app/components/auth/actions';
|
2019-12-07 21:02:00 +02:00
|
|
|
import { ScrollIntoView } from 'app/components/ui/scroll';
|
|
|
|
import PrivateRoute from 'app/containers/PrivateRoute';
|
|
|
|
import AuthFlowRoute from 'app/containers/AuthFlowRoute';
|
2020-07-06 19:29:56 +03:00
|
|
|
import { PopupStack } from 'app/components/ui/popup';
|
2020-01-17 23:37:52 +03:00
|
|
|
import * as loader from 'app/services/loader';
|
2019-12-07 21:02:00 +02:00
|
|
|
import { getActiveAccount } from 'app/components/accounts/reducer';
|
|
|
|
import { User } from 'app/components/user';
|
|
|
|
import { Account } from 'app/components/accounts/reducer';
|
2019-12-30 10:15:40 +02:00
|
|
|
import { ComponentLoader } from 'app/components/ui/loader';
|
2020-10-23 01:23:59 +03:00
|
|
|
import Toolbar from './Toolbar';
|
2016-01-03 23:18:42 +02:00
|
|
|
|
|
|
|
import styles from './root.scss';
|
2016-05-20 00:30:28 +03:00
|
|
|
|
2020-07-21 15:53:34 +03:00
|
|
|
import PageNotFound from 'app/pages/404/PageNotFound';
|
|
|
|
|
2020-10-11 21:19:12 +03:00
|
|
|
const ProfileController = React.lazy(
|
|
|
|
() => import(/* webpackChunkName: "page-profile-all" */ 'app/pages/profile/ProfileController'),
|
2019-12-30 10:15:40 +02:00
|
|
|
);
|
2020-05-24 02:08:24 +03:00
|
|
|
const RulesPage = React.lazy(() => import(/* webpackChunkName: "page-rules" */ 'app/pages/rules/RulesPage'));
|
|
|
|
const DevPage = React.lazy(() => import(/* webpackChunkName: "page-dev-applications" */ 'app/pages/dev/DevPage'));
|
|
|
|
const AuthPage = React.lazy(() => import(/* webpackChunkName: "page-auth" */ 'app/pages/auth/AuthPage'));
|
2019-12-30 10:15:40 +02:00
|
|
|
|
2019-12-10 09:47:32 +02:00
|
|
|
class RootPage extends React.PureComponent<{
|
2020-05-24 02:08:24 +03:00
|
|
|
account: Account | null;
|
|
|
|
user: User;
|
|
|
|
isPopupActive: boolean;
|
|
|
|
onLogoClick: (event: React.MouseEvent<HTMLAnchorElement>) => void;
|
2017-08-22 23:31:41 +03:00
|
|
|
}> {
|
2020-05-24 02:08:24 +03:00
|
|
|
componentDidMount() {
|
|
|
|
this.onPageUpdate();
|
|
|
|
}
|
2017-05-25 22:11:57 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.onPageUpdate();
|
|
|
|
}
|
2017-05-25 22:11:57 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
onPageUpdate() {
|
|
|
|
loader.hide();
|
|
|
|
}
|
2016-06-05 13:31:17 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
render() {
|
|
|
|
const { user, account, isPopupActive, onLogoClick } = this.props;
|
2016-10-09 20:54:35 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
if (document && document.body) {
|
|
|
|
document.body.style.overflow = isPopupActive ? 'hidden' : '';
|
|
|
|
}
|
2017-05-25 22:11:57 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
|
|
|
<div className={styles.root}>
|
|
|
|
<ScrollIntoView top />
|
2017-10-28 16:38:07 +03:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
<div
|
|
|
|
id="view-port"
|
|
|
|
className={clsx(styles.viewPort, {
|
|
|
|
[styles.isPopupActive]: isPopupActive,
|
|
|
|
})}
|
|
|
|
>
|
2020-10-23 01:23:59 +03:00
|
|
|
<Toolbar account={account} onLogoClick={onLogoClick} />
|
2020-05-24 02:08:24 +03:00
|
|
|
<div className={styles.body}>
|
|
|
|
<React.Suspense fallback={<ComponentLoader />}>
|
|
|
|
<Switch>
|
2020-07-21 15:30:18 +03:00
|
|
|
<PrivateRoute path="/profile" component={ProfileController} />
|
2020-05-24 02:08:24 +03:00
|
|
|
<Route path="/404" component={PageNotFound} />
|
|
|
|
<Route path="/rules" component={RulesPage} />
|
|
|
|
<Route path="/dev" component={DevPage} />
|
2019-12-10 09:47:32 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
<AuthFlowRoute
|
|
|
|
exact
|
|
|
|
path="/"
|
|
|
|
key="indexPage"
|
2020-07-21 15:30:18 +03:00
|
|
|
component={user.isGuest ? AuthPage : ProfileController}
|
2020-05-24 02:08:24 +03:00
|
|
|
/>
|
|
|
|
<AuthFlowRoute path="/" component={AuthPage} />
|
2019-12-26 14:18:58 +02:00
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
<Route component={PageNotFound} />
|
|
|
|
</Switch>
|
|
|
|
</React.Suspense>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<PopupStack />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-01-03 23:18:42 +02:00
|
|
|
}
|
2016-02-13 17:28:47 +02:00
|
|
|
|
2020-10-23 01:23:59 +03:00
|
|
|
export default connect(
|
|
|
|
(state) => ({
|
|
|
|
user: state.user,
|
|
|
|
account: getActiveAccount(state),
|
|
|
|
isPopupActive: state.popup.popups.length > 0,
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
onLogoClick: resetAuth,
|
|
|
|
},
|
|
|
|
)(RootPage);
|