Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/components/Layout.jsx
Browse files
frontend/src/components/Layout.jsx
CHANGED
|
@@ -15,6 +15,32 @@ export const Layout = ({ children }) => {
|
|
| 15 |
setGlobalSearchQuery(urlQuery);
|
| 16 |
}, [urlQuery]);
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
const [isDemoMode, setIsDemoMode] = useState(false);
|
| 19 |
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
| 20 |
const [isNotificationsOpen, setIsNotificationsOpen] = useState(false);
|
|
|
|
| 15 |
setGlobalSearchQuery(urlQuery);
|
| 16 |
}, [urlQuery]);
|
| 17 |
|
| 18 |
+
// Restore and persist scroll position across page refresh
|
| 19 |
+
useEffect(() => {
|
| 20 |
+
const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
|
| 21 |
+
const savedScroll = sessionStorage.getItem(scrollKey);
|
| 22 |
+
if (savedScroll) {
|
| 23 |
+
const scrollY = parseInt(savedScroll, 10);
|
| 24 |
+
if (!isNaN(scrollY) && scrollY > 0) {
|
| 25 |
+
const timer = setTimeout(() => {
|
| 26 |
+
window.scrollTo({ top: scrollY, behavior: 'instant' });
|
| 27 |
+
}, 80);
|
| 28 |
+
return () => clearTimeout(timer);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
}, [location.pathname, location.search]);
|
| 32 |
+
|
| 33 |
+
useEffect(() => {
|
| 34 |
+
const handleScroll = () => {
|
| 35 |
+
const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
|
| 36 |
+
sessionStorage.setItem(scrollKey, window.scrollY.toString());
|
| 37 |
+
};
|
| 38 |
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
| 39 |
+
return () => {
|
| 40 |
+
window.removeEventListener('scroll', handleScroll);
|
| 41 |
+
};
|
| 42 |
+
}, [location.pathname, location.search]);
|
| 43 |
+
|
| 44 |
const [isDemoMode, setIsDemoMode] = useState(false);
|
| 45 |
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
| 46 |
const [isNotificationsOpen, setIsNotificationsOpen] = useState(false);
|