11import { useState , useEffect } from 'react' ;
22import Login from './pages/Login' ;
33import Dashboard from './pages/Dashboard' ;
4+ import Settings from './pages/Settings' ;
45import { AuthProvider , useAuth } from './context/AuthContext' ;
6+ import { AppSidebar } from './components/app-sidebar' ;
7+ import { SidebarProvider , SidebarInset , SidebarTrigger , Separator , Breadcrumb , BreadcrumbItem , BreadcrumbList , BreadcrumbPage } from '@objectql/ui' ;
58
69function AppContent ( ) {
710 const { user, loading } = useAuth ( ) ;
811 const [ currentPath , setCurrentPath ] = useState ( window . location . pathname ) ;
12+ // This would ideally come from a context or prop passed from Dashboard,
13+ // but for now we'll fetch objects to pass to Sidebar in AppContent as well if needed,
14+ // or refactor layout.
15+ // ACTUALLY: Dashboard handles the Sidebar usually.
16+ // Let's modify AppContent to render the Main Layout if logged in.
17+
18+ const [ objects , setObjects ] = useState < Record < string , any > > ( { } ) ;
19+
20+ // We need to fetch objects for the sidebar if we are not in dashboard
21+ useEffect ( ( ) => {
22+ if ( user && Object . keys ( objects ) . length === 0 ) {
23+ fetch ( '/api/v6/metadata/object' )
24+ . then ( res => res . json ( ) )
25+ . then ( result => {
26+ const objectsMap : Record < string , any > = { } ;
27+ if ( Array . isArray ( result ) ) {
28+ result . forEach ( ( obj : any ) => {
29+ objectsMap [ obj . name ] = obj ;
30+ } ) ;
31+ }
32+ setObjects ( objectsMap ) ;
33+ } )
34+ . catch ( console . error ) ;
35+ }
36+ } , [ user ] ) ;
937
1038 useEffect ( ( ) => {
1139 const handlePopState = ( ) => setCurrentPath ( window . location . pathname ) ;
1240 window . addEventListener ( 'popstate' , handlePopState ) ;
13- return ( ) => window . removeEventListener ( 'popstate' , handlePopState ) ;
41+
42+ // Custom event for navigation
43+ const handlePushState = ( ) => setCurrentPath ( window . location . pathname ) ;
44+ window . addEventListener ( 'pushstate' , handlePushState ) ;
45+
46+ return ( ) => {
47+ window . removeEventListener ( 'popstate' , handlePopState ) ;
48+ window . removeEventListener ( 'pushstate' , handlePushState ) ;
49+ } ;
1450 } , [ ] ) ;
1551
1652 if ( loading ) {
@@ -21,25 +57,44 @@ function AppContent() {
2157 ) ;
2258 }
2359
24- // Simple routing
25- if ( ! user && currentPath !== '/login' ) {
26- window . history . pushState ( { } , '' , '/login' ) ;
27- // Update state to match new URL to prevent inconsistent state
60+ // Auth Routing
61+ if ( ! user ) {
2862 if ( currentPath !== '/login' ) {
29- setCurrentPath ( '/login' ) ;
63+ window . history . pushState ( { } , '' , '/login' ) ;
64+ return < Login /> ;
3065 }
3166 return < Login /> ;
3267 }
3368
3469 if ( currentPath === '/login' ) {
35- if ( user ) {
36- window . history . pushState ( { } , '' , '/dashboard' ) ;
37- return < Dashboard /> ;
38- }
39- return < Login /> ;
70+ window . history . pushState ( { } , '' , '/' ) ;
71+ setCurrentPath ( '/' ) ;
4072 }
4173
42- return < Dashboard /> ;
74+ // Main Layout
75+ return (
76+ < SidebarProvider >
77+ < AppSidebar objects = { objects } />
78+ < SidebarInset >
79+ < header className = "flex h-16 shrink-0 items-center gap-2 border-b px-4" >
80+ < SidebarTrigger className = "-ml-1" />
81+ < Separator orientation = "vertical" className = "mr-2 h-4" />
82+ < Breadcrumb >
83+ < BreadcrumbList >
84+ < BreadcrumbItem >
85+ < BreadcrumbPage >
86+ { currentPath === '/settings' ? 'Settings' : 'Dashboard' }
87+ </ BreadcrumbPage >
88+ </ BreadcrumbItem >
89+ </ BreadcrumbList >
90+ </ Breadcrumb >
91+ </ header >
92+ < div className = "flex flex-1 flex-col gap-4 p-4" >
93+ { currentPath === '/settings' ? < Settings /> : < Dashboard /> }
94+ </ div >
95+ </ SidebarInset >
96+ </ SidebarProvider >
97+ ) ;
4398}
4499
45100function App ( ) {
@@ -51,3 +106,4 @@ function App() {
51106}
52107
53108export default App ;
109+
0 commit comments