Move up pathname to useUser

This commit is contained in:
Leonardo Murça 2022-06-15 14:36:14 -03:00
parent 24045280c8
commit ab6252e67a
2 changed files with 9 additions and 4 deletions

View file

@ -18,7 +18,6 @@ import { useUser } from './context/user';
function AuthenticatedApp() { function AuthenticatedApp() {
const { state } = useUser(); const { state } = useUser();
const { pathname } = useLocation();
const layoutType = useLayoutType(); const layoutType = useLayoutType();
return ( return (
@ -35,7 +34,10 @@ function AuthenticatedApp() {
maxWidth="false" maxWidth="false"
sx={layoutType === 'desktop' ? container : mobileContainer} sx={layoutType === 'desktop' ? container : mobileContainer}
> >
<MainMenu options={menuOptions(pathname)} layoutType={layoutType} /> <MainMenu
options={menuOptions(state.pathname)}
layoutType={layoutType}
/>
<Routes> <Routes>
<Route path="/home" element={<Home />} /> <Route path="/home" element={<Home />} />
<Route path="/info" element={<Information />} /> <Route path="/info" element={<Information />} />

View file

@ -1,4 +1,5 @@
import { createContext, useContext, useEffect, useState } from 'react'; import { createContext, useContext, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { sleep } from '../utils/sleep'; import { sleep } from '../utils/sleep';
import { useAuthState } from './auth'; import { useAuthState } from './auth';
@ -40,16 +41,18 @@ const UserContext = createContext();
function UserProvider(props) { function UserProvider(props) {
const { user } = useAuthState(); const { user } = useAuthState();
const { pathname } = useLocation();
const [state, setState] = useState({ const [state, setState] = useState({
status: 'idle', status: 'idle',
user: null, user: null,
classrooms: [], classrooms: [],
error: null, error: null,
pathname: '',
}); });
useEffect(() => { useEffect(() => {
setState({ user }); setState({ user, pathname });
}, [user]); }, [user, pathname]);
const classrooms = () => { const classrooms = () => {
setState({ ...state, status: 'pending' }); setState({ ...state, status: 'pending' });