Skip to content

Commit

Permalink
feat: show app loader while loading user session
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Sep 6, 2024
1 parent 67334b6 commit 8424961
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/router/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { BASE_URL } from '../config'
import { Route } from '../sections/Route.enum'
import { useSession } from '../sections/session/SessionContext'
import { Outlet } from 'react-router-dom'
import { AppLoader } from '../sections/shared/layout/app-loader/AppLoader'

export const ProtectedRoute = () => {
const { user, isLoadingUser } = useSession()

if (isLoadingUser) {
//TODO:ME Show app loader here
return null
return <AppLoader />
}

if (!user) {
window.location.href = `${BASE_URL}${Route.LOG_IN}`
return null
}

// TODO: When we have the login page within the SPA, we can use the following code:
// When we have the login page inside the SPA, we can use the following code:
// return !user ? <Navigate to="/login" replace /> : <Outlet />

return <Outlet />
Expand Down
7 changes: 7 additions & 0 deletions src/sections/shared/layout/app-loader/AppLoader.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import 'src/assets/variables';

.app-loader {
display: grid;
place-content: center;
min-height: $body-available-height;
}
10 changes: 10 additions & 0 deletions src/sections/shared/layout/app-loader/AppLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Spinner } from '@iqss/dataverse-design-system'
import styles from './AppLoader.module.scss'

export const AppLoader = () => {
return (
<section className={styles['app-loader']}>
<Spinner />
</section>
)
}

0 comments on commit 8424961

Please sign in to comment.