2024-12-14 17:46:29 +05:30
|
|
|
import React, { FC, useCallback, useEffect } from 'react';
|
2020-10-23 03:53:59 +05:30
|
|
|
import { Route, Switch } from 'react-router-dom';
|
2019-12-08 01:13:08 +05:30
|
|
|
import clsx from 'clsx';
|
2020-07-22 15:31:12 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
import { useReduxSelector, useReduxDispatch } from 'app/functions';
|
2020-07-22 15:31:12 +05:30
|
|
|
import { resetAuth } from 'app/components/auth/actions';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { ScrollIntoView } from 'app/components/ui/scroll';
|
|
|
|
import PrivateRoute from 'app/containers/PrivateRoute';
|
|
|
|
import AuthFlowRoute from 'app/containers/AuthFlowRoute';
|
2020-07-06 21:59:56 +05:30
|
|
|
import { PopupStack } from 'app/components/ui/popup';
|
2020-01-18 02:07:52 +05:30
|
|
|
import * as loader from 'app/services/loader';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { getActiveAccount } from 'app/components/accounts/reducer';
|
2019-12-30 13:45:40 +05:30
|
|
|
import { ComponentLoader } from 'app/components/ui/loader';
|
2024-12-14 17:46:29 +05:30
|
|
|
import PageNotFound from 'app/pages/404/PageNotFound';
|
|
|
|
import DeviceCode from 'app/components/auth/deviceCode';
|
2016-01-04 02:48:42 +05:30
|
|
|
|
|
|
|
import styles from './root.scss';
|
2024-12-14 17:46:29 +05:30
|
|
|
import Toolbar from './Toolbar';
|
2020-07-21 18:23:34 +05:30
|
|
|
|
2020-10-11 23:49:12 +05:30
|
|
|
const ProfileController = React.lazy(
|
|
|
|
() => import(/* webpackChunkName: "page-profile-all" */ 'app/pages/profile/ProfileController'),
|
2019-12-30 13:45:40 +05:30
|
|
|
);
|
2020-05-24 04:38:24 +05:30
|
|
|
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 13:45:40 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
const RootPage: FC = () => {
|
|
|
|
const dispatch = useReduxDispatch();
|
|
|
|
const user = useReduxSelector((state) => state.user);
|
|
|
|
const account = useReduxSelector(getActiveAccount);
|
|
|
|
const isPopupActive = useReduxSelector((state) => state.popup.popups.length > 0);
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
const onLogoClick = useCallback(() => {
|
|
|
|
dispatch(resetAuth());
|
|
|
|
}, []);
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
useEffect(() => {
|
2020-05-24 04:38:24 +05:30
|
|
|
loader.hide();
|
2024-12-14 17:46:29 +05:30
|
|
|
}); // No deps, effect must be called on every update
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
return (
|
|
|
|
<div className={styles.root}>
|
|
|
|
<ScrollIntoView top />
|
2017-10-28 19:08:07 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
<div
|
|
|
|
id="view-port"
|
|
|
|
className={clsx(styles.viewPort, {
|
|
|
|
[styles.isPopupActive]: isPopupActive,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Toolbar account={account} onLogoClick={onLogoClick} />
|
|
|
|
<div className={styles.body}>
|
|
|
|
<React.Suspense fallback={<ComponentLoader />}>
|
|
|
|
<Switch>
|
|
|
|
<PrivateRoute path="/profile" component={ProfileController} />
|
|
|
|
<Route path="/404" component={PageNotFound} />
|
|
|
|
<Route path="/rules" component={RulesPage} />
|
|
|
|
<Route path="/dev" component={DevPage} />
|
2019-12-10 13:17:32 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
<AuthFlowRoute
|
|
|
|
exact
|
|
|
|
path="/"
|
|
|
|
key="indexPage"
|
|
|
|
component={user.isGuest ? AuthPage : ProfileController}
|
|
|
|
/>
|
|
|
|
<AuthFlowRoute exact path="/code" component={DeviceCode} />
|
|
|
|
<AuthFlowRoute path="/" component={AuthPage} />
|
2019-12-26 17:48:58 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
<Route component={PageNotFound} />
|
|
|
|
</Switch>
|
|
|
|
</React.Suspense>
|
2020-05-24 04:38:24 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
2024-12-14 17:46:29 +05:30
|
|
|
<PopupStack />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
export default RootPage;
|