Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/components/Layout.jsx
Browse files
frontend/src/components/Layout.jsx
CHANGED
|
@@ -49,37 +49,12 @@ export const Layout = ({ children }) => {
|
|
| 49 |
setGlobalSearchQuery(urlQuery);
|
| 50 |
}, [urlQuery]);
|
| 51 |
|
| 52 |
-
//
|
| 53 |
useEffect(() => {
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
const scrollY = parseInt(savedScroll, 10);
|
| 59 |
-
if (!isNaN(scrollY) && scrollY > 0) {
|
| 60 |
-
const timer = setTimeout(() => {
|
| 61 |
-
try {
|
| 62 |
-
window.scrollTo(0, scrollY);
|
| 63 |
-
} catch (e) {}
|
| 64 |
-
}, 80);
|
| 65 |
-
return () => clearTimeout(timer);
|
| 66 |
-
}
|
| 67 |
-
}
|
| 68 |
-
} catch (e) {}
|
| 69 |
-
}, [location.pathname, location.search]);
|
| 70 |
-
|
| 71 |
-
useEffect(() => {
|
| 72 |
-
const handleScroll = () => {
|
| 73 |
-
try {
|
| 74 |
-
const scrollKey = `scroll_pos_${location.pathname}${location.search}`;
|
| 75 |
-
sessionStorage.setItem(scrollKey, window.scrollY.toString());
|
| 76 |
-
} catch (e) {}
|
| 77 |
-
};
|
| 78 |
-
window.addEventListener('scroll', handleScroll, { passive: true });
|
| 79 |
-
return () => {
|
| 80 |
-
window.removeEventListener('scroll', handleScroll);
|
| 81 |
-
};
|
| 82 |
-
}, [location.pathname, location.search]);
|
| 83 |
|
| 84 |
const [isDemoMode, setIsDemoMode] = useState(false);
|
| 85 |
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
|
|
|
| 49 |
setGlobalSearchQuery(urlQuery);
|
| 50 |
}, [urlQuery]);
|
| 51 |
|
| 52 |
+
// Always scroll to top of page on route change
|
| 53 |
useEffect(() => {
|
| 54 |
+
window.scrollTo(0, 0);
|
| 55 |
+
const mainElement = document.querySelector('main');
|
| 56 |
+
if (mainElement) mainElement.scrollTop = 0;
|
| 57 |
+
}, [location.pathname]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
const [isDemoMode, setIsDemoMode] = useState(false);
|
| 60 |
const [isProfileOpen, setIsProfileOpen] = useState(false);
|