webserver-framework-frontend/src/App.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

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';
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' }
];
return (
2022-11-17 13:33:59 +01:00
<div className='app'>
<header>
<UserControls />
</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 />}
</div>
);
}
export default App;