Files
fast_api_template/frontend/src/routes/_layout.tsx
T

38 lines
876 B
TypeScript
Raw Normal View History

2024-03-08 14:58:36 +01:00
import { Flex, Spinner } from '@chakra-ui/react'
import { Outlet, createFileRoute, redirect } from '@tanstack/react-router'
2024-03-08 14:58:36 +01:00
import Sidebar from '../components/Common/Sidebar'
import UserMenu from '../components/Common/UserMenu'
import useAuth, { isLoggedIn } from '../hooks/useAuth'
export const Route = createFileRoute('/_layout')({
2024-03-08 14:58:36 +01:00
component: Layout,
beforeLoad: async () => {
if (!isLoggedIn()) {
throw redirect({
to: '/login',
})
}
2024-03-08 14:58:36 +01:00
},
})
function Layout() {
2024-03-08 14:58:36 +01:00
const { isLoading } = useAuth()
2024-03-08 14:58:36 +01:00
return (
<Flex maxW="large" h="auto" position="relative">
<Sidebar />
{isLoading ? (
<Flex justify="center" align="center" height="100vh" width="full">
<Spinner size="xl" color="ui.main" />
</Flex>
2024-03-08 14:58:36 +01:00
) : (
<Outlet />
)}
<UserMenu />
</Flex>
)
}
2024-03-08 14:58:36 +01:00
export default Layout