|
1 | | -import { useState, useEffect, createContext, useContext, useRef, useCallback } from 'react'; |
| 1 | +import { useState, useEffect, createContext, useContext, useRef, useCallback, type ReactNode } from 'react'; |
2 | 2 | import { Outlet } from 'react-router-dom'; |
3 | 3 | import Box from '@mui/material/Box'; |
4 | 4 | import Container from '@mui/material/Container'; |
@@ -50,20 +50,21 @@ const HomeStateContext = createContext<HomeStateContext | null>(null); |
50 | 50 | export function useAppData() { |
51 | 51 | const context = useContext(AppDataContext); |
52 | 52 | if (!context) { |
53 | | - throw new Error('useAppData must be used within Layout'); |
| 53 | + throw new Error('useAppData must be used within AppDataProvider'); |
54 | 54 | } |
55 | 55 | return context; |
56 | 56 | } |
57 | 57 |
|
58 | 58 | export function useHomeState() { |
59 | 59 | const context = useContext(HomeStateContext); |
60 | 60 | if (!context) { |
61 | | - throw new Error('useHomeState must be used within Layout'); |
| 61 | + throw new Error('useHomeState must be used within AppDataProvider'); |
62 | 62 | } |
63 | 63 | return context; |
64 | 64 | } |
65 | 65 |
|
66 | | -export function Layout() { |
| 66 | +// Global provider that wraps the entire router (persists across all pages including InteractivePage) |
| 67 | +export function AppDataProvider({ children }: { children: ReactNode }) { |
67 | 68 | const [specsData, setSpecsData] = useState<SpecInfo[]>([]); |
68 | 69 | const [librariesData, setLibrariesData] = useState<LibraryInfo[]>([]); |
69 | 70 | const [stats, setStats] = useState<{ specs: number; plots: number; libraries: number } | null>(null); |
@@ -117,12 +118,19 @@ export function Layout() { |
117 | 118 | return ( |
118 | 119 | <AppDataContext.Provider value={{ specsData, librariesData, stats }}> |
119 | 120 | <HomeStateContext.Provider value={{ homeState, homeStateRef, setHomeState, saveScrollPosition }}> |
120 | | - <Box sx={{ minHeight: '100vh', bgcolor: '#fafafa', py: 5, position: 'relative' }}> |
121 | | - <Container maxWidth={false} sx={{ px: { xs: 2, sm: 4, md: 8, lg: 12 } }}> |
122 | | - <Outlet /> |
123 | | - </Container> |
124 | | - </Box> |
| 121 | + {children} |
125 | 122 | </HomeStateContext.Provider> |
126 | 123 | </AppDataContext.Provider> |
127 | 124 | ); |
128 | 125 | } |
| 126 | + |
| 127 | +// Layout component for pages with standard layout (HomePage, SpecPage, CatalogPage) |
| 128 | +export function Layout() { |
| 129 | + return ( |
| 130 | + <Box sx={{ minHeight: '100vh', bgcolor: '#fafafa', py: 5, position: 'relative' }}> |
| 131 | + <Container maxWidth={false} sx={{ px: { xs: 2, sm: 4, md: 8, lg: 12 } }}> |
| 132 | + <Outlet /> |
| 133 | + </Container> |
| 134 | + </Box> |
| 135 | + ); |
| 136 | +} |
0 commit comments