2017-06-08 23:29:31 +05:30
|
|
|
import React, { Component } from 'react';
|
2017-09-09 23:31:02 +05:30
|
|
|
import { connect } from 'react-redux';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { resetAuth } from 'app/components/auth/actions';
|
2019-06-30 19:02:50 +05:30
|
|
|
import { withRouter } from 'react-router-dom';
|
2016-05-20 03:00:28 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2017-05-26 00:41:57 +05:30
|
|
|
import { Route, Link, Switch } from 'react-router-dom';
|
2017-06-08 23:29:31 +05:30
|
|
|
import Helmet from 'react-helmet';
|
2016-05-01 23:20:55 +05:30
|
|
|
import classNames from 'classnames';
|
2019-12-08 00:32:00 +05:30
|
|
|
import AuthPage from 'app/pages/auth/AuthPage';
|
|
|
|
import ProfilePage from 'app/pages/profile/ProfilePage';
|
|
|
|
import RulesPage from 'app/pages/rules/RulesPage';
|
|
|
|
import DevPage from 'app/pages/dev/DevPage';
|
|
|
|
import PageNotFound from 'app/pages/404/PageNotFound';
|
|
|
|
import { ScrollIntoView } from 'app/components/ui/scroll';
|
|
|
|
import PrivateRoute from 'app/containers/PrivateRoute';
|
|
|
|
import AuthFlowRoute from 'app/containers/AuthFlowRoute';
|
|
|
|
import Userbar from 'app/components/userbar/Userbar';
|
|
|
|
import PopupStack from 'app/components/ui/popup/PopupStack';
|
|
|
|
import loader from 'app/services/loader';
|
|
|
|
import { getActiveAccount } from 'app/components/accounts/reducer';
|
|
|
|
import { User } from 'app/components/user';
|
|
|
|
import { Account } from 'app/components/accounts/reducer';
|
|
|
|
import { RootState } from 'app/reducers';
|
2016-01-04 02:48:42 +05:30
|
|
|
|
|
|
|
import styles from './root.scss';
|
2016-05-20 03:00:28 +05:30
|
|
|
import messages from './RootPage.intl.json';
|
|
|
|
|
2017-08-23 02:01:41 +05:30
|
|
|
class RootPage extends Component<{
|
2019-12-07 16:58:52 +05:30
|
|
|
account: Account | null;
|
|
|
|
user: User;
|
|
|
|
isPopupActive: boolean;
|
|
|
|
onLogoClick: (event: React.MouseEvent<HTMLAnchorElement>) => void;
|
2019-11-27 14:33:32 +05:30
|
|
|
location: {
|
2019-12-07 16:58:52 +05:30
|
|
|
pathname: string;
|
|
|
|
};
|
2017-08-23 02:01:41 +05:30
|
|
|
}> {
|
2019-11-27 14:33:32 +05:30
|
|
|
componentDidMount() {
|
|
|
|
this.onPageUpdate();
|
|
|
|
}
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
componentDidUpdate() {
|
|
|
|
this.onPageUpdate();
|
|
|
|
}
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
onPageUpdate() {
|
|
|
|
loader.hide();
|
|
|
|
}
|
2016-06-05 16:01:17 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
render() {
|
|
|
|
const { props } = this;
|
|
|
|
const { user, account, isPopupActive, onLogoClick } = this.props;
|
|
|
|
const isRegisterPage = props.location.pathname === '/register';
|
2016-10-09 23:24:35 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
if (document && document.body) {
|
|
|
|
document.body.style.overflow = isPopupActive ? 'hidden' : '';
|
|
|
|
}
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<div className={styles.root}>
|
|
|
|
<Helmet>
|
|
|
|
<html lang={user.lang} />
|
|
|
|
</Helmet>
|
2017-10-28 19:08:07 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
<ScrollIntoView top />
|
2017-10-28 19:08:07 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
<div
|
|
|
|
id="view-port"
|
|
|
|
className={classNames(styles.viewPort, {
|
|
|
|
[styles.isPopupActive]: isPopupActive,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className={styles.header} data-e2e-toolbar>
|
|
|
|
<div className={styles.headerContent}>
|
|
|
|
<Link to="/" className={styles.logo} onClick={onLogoClick}>
|
|
|
|
<Message {...messages.siteName} />
|
|
|
|
</Link>
|
|
|
|
<div className={styles.userbar}>
|
|
|
|
<Userbar
|
|
|
|
account={account}
|
|
|
|
guestAction={isRegisterPage ? 'login' : 'register'}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-01-04 02:48:42 +05:30
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
</div>
|
|
|
|
<div className={styles.body}>
|
|
|
|
<Switch>
|
|
|
|
<PrivateRoute path="/profile" component={ProfilePage} />
|
|
|
|
<Route path="/404" component={PageNotFound} />
|
|
|
|
<Route path="/rules" component={RulesPage} />
|
|
|
|
<Route path="/dev" component={DevPage} />
|
|
|
|
<AuthFlowRoute exact path="/" component={ProfilePage} />
|
|
|
|
<AuthFlowRoute path="/" component={AuthPage} />
|
|
|
|
<Route component={PageNotFound} />
|
|
|
|
</Switch>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<PopupStack />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-01-04 02:48:42 +05:30
|
|
|
}
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
export default withRouter(
|
|
|
|
connect(
|
2019-12-07 16:58:52 +05:30
|
|
|
(state: RootState) => ({
|
2019-11-27 14:33:32 +05:30
|
|
|
user: state.user,
|
|
|
|
account: getActiveAccount(state),
|
|
|
|
isPopupActive: state.popup.popups.length > 0,
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
onLogoClick: resetAuth,
|
|
|
|
},
|
|
|
|
)(RootPage),
|
|
|
|
);
|