Skip to content

Commit

Permalink
Merge pull request #108 from MargoMarm/revert-107-bagfix/retinaImg
Browse files Browse the repository at this point in the history
Revert "update"
  • Loading branch information
nzend committed Sep 29, 2023
2 parents 389bbdf + 91f4d05 commit a0391cf
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 53 deletions.
17 changes: 4 additions & 13 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { fetchCurrentUser } from './redux/auth/operation';

import SharedLayout from './components/SharedLayout/SharedLayout';

import {
PrivateRoute,
PublicRoute,
RestrictedRoute,
} from './components/Routes';
import { PrivateRoute, PublicRoute } from './components/Routes';
import { UseAuth } from './hooks/useAuth';

const Home = lazy(() => import('../src/pages/Home/Home'));
Expand All @@ -31,11 +27,9 @@ const Profile = lazy(() => import('./pages/Profile/Profile'));
function App() {
const dispatch = useDispatch();

const { isRefreshing, isLoggedIn, user } = UseAuth();
const { isRefreshing, isLoggedIn } = UseAuth();
const { pathname } = useLocation();

const emptyUserParams = Object.keys(user.bodyParameters).length === 0;

if (isLoggedIn && pathname !== '/') {
localStorage.setItem('location', pathname);
}
Expand All @@ -59,10 +53,7 @@ function App() {
<Route
path="/signin"
element={
<PublicRoute
component={<SignIn />}
redirectTo={emptyUserParams ? '/params' : '/diary'}
/>
<PublicRoute component={<SignIn />} redirectTo={'/diary'} />
}
/>
<Route
Expand All @@ -77,7 +68,7 @@ function App() {
/>
<Route
path="/params"
element={<RestrictedRoute component={<Params />} redirectTo="/" />}
element={<PrivateRoute component={<Params />} redirectTo="/" />}
/>
<Route
path="/exercises"
Expand Down
10 changes: 2 additions & 8 deletions src/components/Routes/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ import PropTypes from 'prop-types';
import { UseAuth } from '../../hooks/useAuth';

const PrivateRoute = ({ component, redirectTo = '/' }) => {
const { isLoggedIn, isRefreshing, user } = UseAuth();
const { isLoggedIn, isRefreshing } = UseAuth();
const shouldRedirect = isLoggedIn && !isRefreshing;

const emptyUserParams = Object.keys(user.bodyParameters).length === 0;

return shouldRedirect ? (
component
) : (
<Navigate to={emptyUserParams ? '/params' : redirectTo} />
);
return shouldRedirect ? component : <Navigate to={redirectTo} />;
};

PrivateRoute.propTypes = {
Expand Down
17 changes: 0 additions & 17 deletions src/components/Routes/RestrictedRoute.jsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Routes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as PrivateRoute } from './PrivateRoute';
export { default as PublicRoute } from './PublicRoute';
export { default as RestrictedRoute } from './RestrictedRoute';
16 changes: 2 additions & 14 deletions src/pages/Error/Error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ import sprite from '../../assets/sprite.svg';
import { UseAuth } from '../../hooks/useAuth';

const Error = () => {
const { isLoggedIn, user } = UseAuth();

const emptyUserParams = Object.keys(user.bodyParameters).length === 0;

const redirectRoute = () => {
if (isLoggedIn && emptyUserParams) {
return '/params';
} else if (isLoggedIn && !emptyUserParams) {
return 'diary';
} else if (isLoggedIn === false) {
return '/';
}
};
const { isLoggedIn } = UseAuth();

return (
<main>
Expand All @@ -51,7 +39,7 @@ const Error = () => {
type="button"
text={'Go Home'}
isorange={'true'}
to={redirectRoute()}
to={isLoggedIn ? '/diary' : '/'}
/>
</Content>

Expand Down

0 comments on commit a0391cf

Please sign in to comment.