Skip to content

Commit

Permalink
chore: a new skeleton was created
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Feb 27, 2024
1 parent 3c86a54 commit 039b18c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';
import { Navigate } from 'react-router-dom';

import { useAuth } from '@contexts/AuthContext';
import { SkeletonAllBooks } from '@components/skeletons/SkeletonABooks';
import { SkeletonMain } from '@components/skeletons/SkeletonMain';

export function PrivateRoute({ children }: { children: React.ReactNode }) {
const { currentUser, loading } = useAuth();

if (loading) {
return <SkeletonAllBooks />;
return <SkeletonMain />;
}

return currentUser ? <>{children}</> : <Navigate to='/login' />;
Expand Down
13 changes: 13 additions & 0 deletions src/components/skeletons/SkeletonMain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { Skeleton, Stack } from '@chakra-ui/react';

export function SkeletonMain() {
return (
<>
<Stack spacing='4'>
<Skeleton py={{ base: 16, md: 20 }} />
<Skeleton h='100vh' />
</Stack>
</>
);
}
11 changes: 2 additions & 9 deletions src/pages/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Suspense } from 'react';
import { Outlet } from 'react-router-dom';
import { Skeleton, Stack } from '@chakra-ui/react';

import { SkeletonMain } from '@components/skeletons/SkeletonMain';
import { Nav } from '@components/nav/Nav';
import { Footer } from '@components/Footer';
import { ScrollToTop } from '@utils/ScrollToTop';
Expand All @@ -11,14 +11,7 @@ export function Layout() {
<>
<ScrollToTop>
<Nav />
<Suspense
fallback={
<Stack spacing='4'>
<Skeleton py={{ base: 16, md: 20 }} />
<Skeleton h='100vh' />
</Stack>
}
>
<Suspense fallback={<SkeletonMain />}>
<Outlet />
</Suspense>
<Footer />
Expand Down

0 comments on commit 039b18c

Please sign in to comment.