larxius commited on
Commit
952b165
·
verified ·
1 Parent(s): c6d4f4b

Update frontend/src/components/Layout.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/components/Layout.jsx +26 -0
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);