2022-11-17 13:33:59 +01:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { BrowserRouter, Route, Routes} from 'react-router-dom';
|
|
|
|
|
|
|
|
import './css/App.css';
|
|
|
|
import Home from './pages/Home';
|
|
|
|
import ErrorBoundary from './util/ErrorBoundary';
|
|
|
|
import Sidebar, { SidebarMenu } from './components/Sidebar';
|
|
|
|
import UserControls from './components/UserControls';
|
|
|
|
import { useLoginContext } from './structures/UserContext';
|
|
|
|
import Login from './pages/Login';
|
|
|
|
import { fetchUser } from './util/Util';
|
2022-11-15 19:33:00 +01:00
|
|
|
|
|
|
|
function App() {
|
2022-11-17 13:33:59 +01:00
|
|
|
|
|
|
|
const [user] = useLoginContext();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchUser();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const menuItems = [
|
|
|
|
{ to: '/', label: 'Home' },
|
|
|
|
{ to: '/users', label: 'Users' },
|
|
|
|
{ to: '/admin', label: 'Admin' }
|
2022-11-17 22:11:52 +01:00
|
|
|
|
2022-11-17 13:33:59 +01:00
|
|
|
];
|
|
|
|
|
2022-11-15 19:33:00 +01:00
|
|
|
return (
|
2022-11-17 13:33:59 +01:00
|
|
|
<div className='app'>
|
|
|
|
|
|
|
|
<header>
|
|
|
|
<UserControls />
|
2022-11-15 19:33:00 +01:00
|
|
|
</header>
|
2022-11-17 13:33:59 +01:00
|
|
|
|
|
|
|
{user ?
|
|
|
|
<div className='background'>
|
|
|
|
|
|
|
|
<BrowserRouter>
|
|
|
|
|
|
|
|
<Sidebar>
|
|
|
|
SIDEBAR
|
|
|
|
<SidebarMenu menuItems={menuItems}>
|
|
|
|
|
|
|
|
</SidebarMenu>
|
|
|
|
</Sidebar>
|
|
|
|
|
|
|
|
<div className='main-content'>
|
|
|
|
<ErrorBoundary>
|
|
|
|
<Routes>
|
|
|
|
<Route exact path='/' element={<Home />} />
|
|
|
|
</Routes>
|
|
|
|
</ErrorBoundary>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</BrowserRouter>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
: <Login />}
|
|
|
|
|
2022-11-15 19:33:00 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|