35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import { useLocation } from 'react-router-dom';
|
|
import { Sidebar } from './Sidebar';
|
|
import { MobileBack, MobileTabBar } from './MobileNavigation';
|
|
import { useAuth } from '../../context/AuthContext';
|
|
import { useIsMobile } from '../../hooks/useMediaQuery';
|
|
import { paths } from '../../lib/routes';
|
|
|
|
export const AppShell: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
const location = useLocation();
|
|
const isMobile = useIsMobile();
|
|
const { user, stopImpersonation } = useAuth();
|
|
const impersonating = Boolean(user?.impersonatedBy);
|
|
|
|
useEffect(() => {
|
|
window.scrollTo(0, 0);
|
|
document.body.classList.toggle('immersive', location.pathname.includes('/aulas/'));
|
|
return () => document.body.classList.remove('immersive');
|
|
}, [location.pathname]);
|
|
|
|
return (
|
|
<>
|
|
{impersonating && <div className="impersonation-banner" role="status">
|
|
<span>Você está vendo a plataforma como <b>{user?.name}</b>.</span>
|
|
<button type="button" onClick={async () => { if (await stopImpersonation()) window.location.assign(paths.admin); }}>Sair da impersonação</button>
|
|
</div>}
|
|
{!isMobile && <Sidebar />}
|
|
{isMobile && <MobileBack />}
|
|
{/* Keyed by path: the arrival animation only plays when navigating to a new page. */}
|
|
<div className="main" key={location.pathname}>{children}</div>
|
|
{isMobile && <MobileTabBar />}
|
|
</>
|
|
);
|
|
};
|