fix funky rendering when logged in from a previous session
This commit is contained in:
parent
cab064a143
commit
25ed91477d
23
src/App.js
23
src/App.js
@ -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 ?
|
||||||
|
<div>
|
||||||
|
<header className="card">
|
||||||
|
<UserControls />
|
||||||
|
</header>
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
<SidebarMenu menuItems={menuItems} />
|
<SidebarMenu menuItems={menuItems} />
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
|
</div>
|
||||||
: null}
|
: null}
|
||||||
|
|
||||||
<div className='main-content'>
|
<div className='main-content'>
|
||||||
|
Loading…
Reference in New Issue
Block a user