Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBC22-1841: fixed scrollto being triggered multiple times #318

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/frontend/src/pages/CamerasListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@ export default function CamerasListPage() {
const [searchText, setSearchText] = useState('');

// UseEffect hooks and data functions
useEffect(() => {
const scrollPosition = sessionStorage.getItem('scrollPosition');
if (scrollPosition) {
window.scrollTo(0, parseInt(scrollPosition, 10));
}
});

const getCamerasData = async () => {
isInitialMount.current = false;

const newRouteTimestamp = selectedRoute ? selectedRoute.searchTimestamp : null;

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

}, [searchText, processedCameras]);

useEffect(() => {
if (isInitialMount.current) {
const scrollPosition = sessionStorage.getItem('scrollPosition');
if (scrollPosition) {
setTimeout(function() {
window.scrollTo({
top: parseInt(scrollPosition, 10),
left: 0,
behavior: "smooth"
});
}, 300);
}

isInitialMount.current = false;
}
}, [displayedCameras]);

return (
<div className="cameras-page">
<PageHeader
Expand Down
Loading