Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect fixes #137

Merged
merged 1 commit into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions client/src/components/authorization/CheckLoggedIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ import { Redirect } from "react-router-dom";
import { useGetData } from "use-axios-react";
import { connect } from "react-redux";
import { verifyLogin } from "../../redux/actions/auth";
import { makeStyles } from '@material-ui/core/styles';
import LinearProgress from '@material-ui/core/LinearProgress';
import CircularProgress from '@material-ui/core/CircularProgress';
import { makeStyles } from "@material-ui/core/styles";
import LinearProgress from "@material-ui/core/LinearProgress";
import CircularProgress from "@material-ui/core/CircularProgress";

const CheckLoggedIn = ({ verifyLogin }) => {
useEffect(() => {
verifyLogin();
}, [verifyLogin]);
const [userInfo, loading] = useGetData("/api/current_user");
const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles(theme => ({
root: {
width: '100%',
'& > * + *': {
marginTop: theme.spacing(2),
},
},
width: "100%",
"& > * + *": {
marginTop: theme.spacing(2)
}
}
}));

const useStylesCircular = makeStyles((theme) => ({
const useStylesCircular = makeStyles(theme => ({
root: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
'& > * + *': {
display: "flex",
alignItems: "center",
justifyContent: "center",
"& > * + *": {
marginLeft: theme.spacing(2),
marginTop: theme.spacing(2),
},
},
marginTop: theme.spacing(2)
}
}
}));
const Cclasses = useStylesCircular();
const classes = useStyles();
if (loading) {
if (loading || (localStorage.getItem("loggedIn") && !userInfo)) {
return (
<>
<div className={classes.root}>
Expand All @@ -43,7 +43,8 @@ const CheckLoggedIn = ({ verifyLogin }) => {
<div className={Cclasses.root}>
<CircularProgress />
</div>
</>/*<Redirect to='/checkloggedin'></Redirect>*/);
</> /*<Redirect to='/checkloggedin'></Redirect>*/
);
} else if (!userInfo) {
return <Redirect to='/'></Redirect>;
} else {
Expand Down
34 changes: 32 additions & 2 deletions client/src/components/routes/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { useGetData } from "use-axios-react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { verifyLogin } from "../../redux/actions/auth";
import { makeStyles } from "@material-ui/core/styles";
import LinearProgress from "@material-ui/core/LinearProgress";
import CircularProgress from "@material-ui/core/CircularProgress";

const PrivateRoute = ({
component: Component,
Expand All @@ -13,16 +16,43 @@ const PrivateRoute = ({
...rest
}) => {
const [userInfo, loading] = useGetData("/api/current_user");
const useStyles = makeStyles(theme => ({
root: {
width: "100%",
"& > * + *": {
marginTop: theme.spacing(2)
}
}
}));

const useStylesCircular = makeStyles(theme => ({
root: {
display: "flex",
alignItems: "center",
justifyContent: "center",
"& > * + *": {
marginLeft: theme.spacing(2),
marginTop: theme.spacing(2)
}
}
}));
const Cclasses = useStylesCircular();
const classes = useStyles();
return (
<Route
{...rest}
render={props =>
!localStorage.getItem("loggedIn") ? (
<Redirect to='/'></Redirect>
) : loading ? (
// Put a cool animation here
<div>Loading...</div>
<>
<div className={classes.root}>
<LinearProgress />
</div>
<div className={Cclasses.root}>
<CircularProgress />
</div>
</>
) : !((!submitted && userInfo.submittedForm) || submitted) ? (
<Redirect to='/helform'></Redirect>
) : (
Expand Down
12 changes: 8 additions & 4 deletions client/src/components/tabs/Landing.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from "react";
import "../../styles/Landing.css";
import configuration from "../../config/constants.js";
import { useGetData } from "use-axios-react";
import { Redirect } from "react-router-dom";

export const Landing = () => {
return (
const [userInfo, loading] = useGetData("/api/current_user");
return userInfo && localStorage.getItem("loggedIn") ? (
<Redirect to='/checkloggedin'></Redirect>
) : (
<section className='landing body'>
<div className='dark-overlay'>
<div className='landing-inner'>
Expand All @@ -26,11 +32,9 @@ export const Landing = () => {
</div>
</div>
</div>
<div>
</div>
<div></div>
</section>
);
};


export default Landing;