init website
This commit is contained in:
82
src/main/webapp/src/App.jsx
Normal file
82
src/main/webapp/src/App.jsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import {useEffect, useRef} from 'react'
|
||||
import './App.css'
|
||||
import {Nav} from "./components/Nav.jsx";
|
||||
import {createBrowserRouter, Outlet, RouterProvider, useRouteError} from "react-router-dom";
|
||||
import {Home} from "./pages/Homepage.jsx";
|
||||
import {AdminRoot} from "./pages/admin/AdminRoot.jsx";
|
||||
import {AuthCallback} from "./components/auhCallback.jsx";
|
||||
import {useAuthDispatch} from "./hooks/useAuth.jsx";
|
||||
import {check_validity} from "./utils/auth.js";
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
element: <Root/>,
|
||||
errorElement: <PageError/>,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
element: <Home/>
|
||||
},
|
||||
{
|
||||
path: 'admin',
|
||||
element: <AdminRoot/>,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
element: <div>Admin</div>
|
||||
},
|
||||
{
|
||||
path: 'b',
|
||||
element: <div>Admin B</div>
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/complete/auth',
|
||||
element: <AuthCallback/>
|
||||
}
|
||||
])
|
||||
|
||||
function PageError() {
|
||||
const error = useRouteError()
|
||||
return <div style={{textAlign: 'center'}}>
|
||||
<h1>Une erreur est survenue</h1>
|
||||
<p>
|
||||
{error?.error?.toString() ?? error?.toString()}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
function Root() {
|
||||
return <>
|
||||
<header>
|
||||
<Nav/>
|
||||
</header>
|
||||
<div className="container my-4">
|
||||
<Outlet/>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
function App() {
|
||||
console.log('render')
|
||||
|
||||
const dispatch = useAuthDispatch()
|
||||
const isInit = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (isInit.current)
|
||||
return;
|
||||
isInit.current = true
|
||||
check_validity(b => dispatch({type: 'init', val: b}))
|
||||
}, []);
|
||||
|
||||
|
||||
|
||||
return <RouterProvider router={router}/>;
|
||||
}
|
||||
|
||||
export default App
|
||||
Reference in New Issue
Block a user