Files
compor-academy/components/shell/AppShell.tsx
Cauê Faleiros 50905eefd7
All checks were successful
CI / Validate frontend and API (push) Successful in 3m5s
CI / Build and publish Docker images (push) Successful in 1m42s
feat: add 2FA, secure cookies and publishing tools
2026-11-06 10:29:37 -03:00

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 />}
</>
);
};