Skip to content

Commit 0e41d71

Browse files
committed
DBC22-1841: fixed scrollto being triggered multiple times
1 parent a667094 commit 0e41d71

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/frontend/src/pages/CamerasListPage.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,7 @@ export default function CamerasListPage() {
4141
const [searchText, setSearchText] = useState('');
4242

4343
// UseEffect hooks and data functions
44-
useEffect(() => {
45-
const scrollPosition = sessionStorage.getItem('scrollPosition');
46-
if (scrollPosition) {
47-
window.scrollTo(0, parseInt(scrollPosition, 10));
48-
}
49-
});
50-
5144
const getCamerasData = async () => {
52-
isInitialMount.current = false;
53-
5445
const newRouteTimestamp = selectedRoute ? selectedRoute.searchTimestamp : null;
5546

5647
let tempCams = cameras;
@@ -100,6 +91,23 @@ export default function CamerasListPage() {
10091

10192
}, [searchText, processedCameras]);
10293

94+
useEffect(() => {
95+
if (isInitialMount.current) {
96+
const scrollPosition = sessionStorage.getItem('scrollPosition');
97+
if (scrollPosition) {
98+
setTimeout(function() {
99+
window.scrollTo({
100+
top: parseInt(scrollPosition, 10),
101+
left: 0,
102+
behavior: "smooth"
103+
});
104+
}, 300);
105+
}
106+
107+
isInitialMount.current = false;
108+
}
109+
}, [displayedCameras]);
110+
103111
return (
104112
<div className="cameras-page">
105113
<PageHeader

0 commit comments

Comments
 (0)