fix funky rendering when logged in from a previous session

This commit is contained in:
Erik 2022-11-24 00:04:28 +02:00
parent cab064a143
commit 25ed91477d
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -1,4 +1,4 @@
import React, { useEffect } from 'react'; import React, { useEffect, useState } from 'react';
import { BrowserRouter, Navigate, Route, Routes} from 'react-router-dom'; import { BrowserRouter, Navigate, Route, Routes} from 'react-router-dom';
import './css/App.css'; import './css/App.css';
@ -16,34 +16,41 @@ import Admin from './pages/Admin';
function App() { function App() {
const [user] = useLoginContext(); const [user, updateUser] = useLoginContext();
const [loading, setLoading] = useState(true);
useEffect(() => { useEffect(() => {
fetchUser(); (async () => {
await fetchUser();
updateUser();
setLoading(false);
})();
}, []); }, []);
const menuItems = [ const menuItems = [
{ to: '/home', label: 'Home' }, { to: '/home', label: 'Home' },
{ to: '/users', label: 'Users' }, { to: '/users', label: 'Users' },
{ to: '/admin', label: 'Admin' } { to: '/admin', label: 'Admin' }
];
]; if (loading) return null;
return ( return (
<div className='app is-full-screen'> <div className='app is-full-screen'>
<header className="card">
<UserControls />
</header>
<div className='background'> <div className='background'>
<BrowserRouter> <BrowserRouter>
{user ? {user ?
<Sidebar> <div>
<SidebarMenu menuItems={menuItems} /> <header className="card">
</Sidebar> <UserControls />
</header>
<Sidebar>
<SidebarMenu menuItems={menuItems} />
</Sidebar>
</div>
: null} : null}
<div className='main-content'> <div className='main-content'>