Spaces:
Paused
Paused
Download frontend/src/app/layout.tsx from data-llm-hub/tensorwall: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/data-llm-hub/tensorwall/resolve/main/frontend/src/app/layout.tsx
- Command line
-
hf download hf://spaces/data-llm-hub/tensorwall/frontend/src/app/layout.tsx
-
curl -L -o layout.tsx https://huggingface.co/spaces/data-llm-hub/tensorwall/resolve/main/frontend/src/app/layout.tsx
2.21 kB
| 'use client'; | |
| import './globals.css'; | |
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | |
| import { useState, useEffect } from 'react'; | |
| import { usePathname, useRouter } from 'next/navigation'; | |
| import { AuthProvider, useAuth } from '@/lib/auth-context'; | |
| import { PermissionProvider } from '@/contexts/PermissionContext'; | |
| import Sidebar from '@/components/Sidebar'; | |
| import { Loader2 } from 'lucide-react'; | |
| function AuthenticatedLayout({ children }: { children: React.ReactNode }) { | |
| const pathname = usePathname(); | |
| const router = useRouter(); | |
| const { isLoading, isAuthenticated } = useAuth(); | |
| // Redirect to login if not authenticated (client-side) | |
| useEffect(() => { | |
| if (!isLoading && !isAuthenticated && pathname !== '/login') { | |
| router.push('/login'); | |
| } | |
| }, [isLoading, isAuthenticated, pathname, router]); | |
| // Don't show sidebar on login page | |
| if (pathname === '/login') { | |
| return <>{children}</>; | |
| } | |
| // Show loading state while checking auth or redirecting | |
| if (isLoading || !isAuthenticated) { | |
| return ( | |
| <div className="min-h-screen bg-gray-900 flex items-center justify-center"> | |
| <div className="text-center"> | |
| <Loader2 className="w-8 h-8 text-blue-500 animate-spin mx-auto mb-4" /> | |
| <p className="text-gray-400">Loading...</p> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| // Show authenticated layout with sidebar | |
| return ( | |
| <div className="min-h-screen bg-gray-100"> | |
| <Sidebar /> | |
| <main className="lg:pl-64"> | |
| <div className="p-6 lg:p-8">{children}</div> | |
| </main> | |
| </div> | |
| ); | |
| } | |
| export default function RootLayout({ | |
| children, | |
| }: { | |
| children: React.ReactNode; | |
| }) { | |
| const [queryClient] = useState(() => new QueryClient({ | |
| defaultOptions: { | |
| queries: { | |
| retry: 1, | |
| refetchOnWindowFocus: false, | |
| }, | |
| }, | |
| })); | |
| return ( | |
| <html lang="en"> | |
| <body> | |
| <QueryClientProvider client={queryClient}> | |
| <AuthProvider> | |
| <PermissionProvider> | |
| <AuthenticatedLayout>{children}</AuthenticatedLayout> | |
| </PermissionProvider> | |
| </AuthProvider> | |
| </QueryClientProvider> | |
| </body> | |
| </html> | |
| ); | |
| } | |