Skip to content

Commit

Permalink
LazyLoaded routes
Browse files Browse the repository at this point in the history
  • Loading branch information
FLiotta committed Oct 15, 2020
1 parent 648edae commit ce6c246
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 39 deletions.
14 changes: 0 additions & 14 deletions client/src/components/utils/LazyLoad.tsx

This file was deleted.

18 changes: 10 additions & 8 deletions client/src/pages/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Loading from '../../components/Loading';
import GithubOAuth from '../../components/OAuth/Github';
import { logIn, signUp, oauthGithub } from '../../actions/session';
import { isLoggedSelector, isSessionFetching } from '../../selectors/session';
import { RECAPTCHA_SITE_KEY } from '../../config';
import { RECAPTCHA_SITE_KEY, RECAPTCHA_AVAILABLE } from '../../config';
import './styles.scss';

interface IAccount {
Expand All @@ -25,13 +25,13 @@ interface IPropsForm {
btnText: string
};

const AuthForm = ({ onSubmit, btnText }: IPropsForm): JSX.Element => {
export const AuthForm = ({ onSubmit, btnText }: IPropsForm): JSX.Element => {
const [recaptchaStatus, setRecaptchaStatus] = useState(false);
const { handleSubmit, register, errors } = useForm();

return (
<form onSubmit={handleSubmit((e) => {
if (recaptchaStatus) {
if (recaptchaStatus || !RECAPTCHA_AVAILABLE) {
onSubmit(e)
}
})}>
Expand All @@ -49,11 +49,13 @@ const AuthForm = ({ onSubmit, btnText }: IPropsForm): JSX.Element => {
ref={register({ required: "Required" })}
placeholder="Password" />
</div>
<ReCAPTCHA
sitekey={RECAPTCHA_SITE_KEY}
onChange={() => setRecaptchaStatus(true)}
onExpired={() => setRecaptchaStatus(false)}
/>
{RECAPTCHA_AVAILABLE &&
<ReCAPTCHA
sitekey={RECAPTCHA_SITE_KEY}
onChange={() => setRecaptchaStatus(true)}
onExpired={() => setRecaptchaStatus(false)}
/>
}
<div className="auth__modal-form-node">
<button type="submit" className="btn btn--block">{btnText}</button>
</div>
Expand Down
38 changes: 21 additions & 17 deletions client/src/routes/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { Fragment } from 'react';
import React, { Fragment, Suspense, lazy } from 'react';
import { IRootReducer } from '../reducers/rootReducer';
import { connect } from 'react-redux';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import ProtectedRoute from '../components/utils/ProtectedRoute';
import Auth from '../pages/Auth';
import AuthCallback from '../pages/AuthCallback';
import Boards from '../pages/Boards';
import Board from '../pages/Board';
import Navbar from '../components/Navbar';
import Landing from '../pages/Landing';
import CookiesModal from '../components/CookiesModal';
import Loading from '../components/Loading';
import Auth from '../pages/Auth';
const AuthCallback = lazy(() => import('../pages/AuthCallback'));
const Boards = lazy(() => import('../pages/Boards'));
const Board = lazy(() => import('../pages/Board'));
const Navbar = lazy(() => import('../components/Navbar'));


interface IAppRouter {
cookiesModalVisible: boolean;
Expand All @@ -21,17 +23,19 @@ const AppRouter = ({
<Fragment>
<BrowserRouter>
{cookiesModalVisible && <CookiesModal />}
<Switch>
<Route path="/" component={Landing} exact />
<Route path="/home" component={Landing} />
<Route path="/auth/callback" component={AuthCallback} />
<Route path="/auth" component={Auth} />
<Fragment>
<Navbar />
<ProtectedRoute path="/b/:id" component={Board} />
<ProtectedRoute path="/boards" component={Boards} />
</Fragment>
</Switch>
<Suspense fallback={<Loading display />}>
<Switch>
<Route path="/" component={Landing} exact />
<Route path="/home" component={Landing} />
<Route path="/auth/callback" component={AuthCallback} />
<Route path="/auth" component={Auth} />
<Fragment>
<Navbar />
<ProtectedRoute path="/b/:id" component={Board} />
<ProtectedRoute path="/boards" component={Boards} />
</Fragment>
</Switch>
</Suspense>
</BrowserRouter>
</Fragment>
);
Expand Down

0 comments on commit ce6c246

Please sign in to comment.