-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathMainLayout.jsx
More file actions
79 lines (70 loc) · 3.37 KB
/
Copy pathMainLayout.jsx
File metadata and controls
79 lines (70 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { useState } from 'react';
import { useLocation, matchPath } from 'react-router-dom';
import Sidebar from './Sidebar';
import Header from './Header';
import ProjectNavbar from './ProjectNavbar';
// Use the new official logo from public directory
const logoImage = "/urBACKEND_NAV_LOGO (2).png";
/**
* App shell that renders the global sidebar, header, or a project-specific navbar and places page content.
*
* Renders a mobile overlay and global sidebar/header when not on a project route; renders a project navbar and a full-width main area when the current path matches `/project/:projectId/*`. Adjusts top padding and content padding for project routes and for paths that include `/database`.
*
* @param {object} props - Component props.
* @param {import('react').ReactNode} props.children - The page content to render inside the layout.
* @returns {JSX.Element} The composed layout element containing navigation and the provided children.
*/
function MainLayout({ children }) {
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
const location = useLocation();
// Check if we are inside a project route to toggle layout mode
// Paths like /project/:projectId/...
const isProjectRoute = matchPath("/project/:projectId/*", location.pathname);
return (
<div className="app-shell">
{/* Mobile Overlay - Only visible when sidebar is open on mobile */}
{isSidebarOpen && !isProjectRoute && (
<div
className="sidebar-overlay"
onClick={() => setIsSidebarOpen(false)}
></div>
)}
{/* Sidebar - Only show if NOT in a project route (or if we want global sidebar always, but plan said hide it) */}
{!isProjectRoute && (
<Sidebar
logo={logoImage}
isOpen={isSidebarOpen}
onClose={() => setIsSidebarOpen(false)}
/>
)}
{/* Main Content Area */}
{/* If Project Route, remove margin-left (full width) */}
{/* Add paddingTop to account for fixed global header only if not in project route */}
<div className={`main-content ${isProjectRoute ? 'full-width' : ''}`} style={{ paddingTop: isProjectRoute ? '0' : 'var(--header-height)' }}>
{/* Global Header */}
{!isProjectRoute && (
<Header
logo={logoImage}
onToggleSidebar={() => setIsSidebarOpen(!isSidebarOpen)}
// Hide toggle button if sidebar is hidden
showToggle={true}
/>
)}
{/* Project Navigation Bar - Only visible in project routes */}
{isProjectRoute && <ProjectNavbar />}
{/* Dynamic Page Content */}
{/* Remove default margin-top as main-content has padding now. Remove padding for Database page. */}
<div
className="content-wrapper"
style={{
marginTop: 0,
padding: isProjectRoute && location.pathname.includes('/database') ? 0 : undefined
}}
>
{children}
</div>
</div>
</div>
);
}
export default MainLayout;