Skip to content

Commit

Permalink
use 'beforeunload'
Browse files Browse the repository at this point in the history
  • Loading branch information
brunovjk committed Jul 2, 2024
1 parent 4622e19 commit 5ec7694
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,30 @@ function ReportActionsList({
};
}, [report.reportID]);

const clearHighLight = () => {
if (!linkedReportActionID || linkedReportActionID === '-1') {
return;
}
Navigation.setParams({reportActionID: '-1'});
};

useEffect(() => {
if (typeof window === 'undefined') {
return;
}

const handleBeforeUnload = () => {
clearHighLight();
};

window.addEventListener('beforeunload', handleBeforeUnload);

return () => {
window.removeEventListener('beforeunload', handleBeforeUnload);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (linkedReportActionID) {
return;
Expand All @@ -345,8 +369,12 @@ function ReportActionsList({
if (!isFromCurrentUser || !hasNewestReportActionRef.current) {
return;
}
InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom());
InteractionManager.runAfterInteractions(() => {
clearHighLight();
reportScrollManager.scrollToBottom();
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[reportScrollManager],
);
useEffect(() => {
Expand Down

0 comments on commit 5ec7694

Please sign in to comment.