fix auto refresh on tab switch
This commit is contained in:
parent
38e45f3cb3
commit
b0aa2020c4
2 changed files with 21 additions and 2 deletions
|
@ -152,10 +152,13 @@ try {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Refresh the page when the user navigates back to it
|
// Remove the visibilitychange event listener that causes full page refresh
|
||||||
|
// Instead, we'll use a more efficient approach to refresh data only when needed
|
||||||
document.addEventListener("visibilitychange", () => {
|
document.addEventListener("visibilitychange", () => {
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") {
|
||||||
window.location.reload();
|
// Instead of reloading the entire page, dispatch a custom event
|
||||||
|
// that components can listen for to refresh their data
|
||||||
|
document.dispatchEvent(new CustomEvent("dashboardTabVisible"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,22 @@ const EventRequestManagementTable = ({ eventRequests: initialEventRequests }: Ev
|
||||||
refreshEventRequests();
|
refreshEventRequests();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Listen for tab visibility changes and refresh data when tab becomes visible
|
||||||
|
useEffect(() => {
|
||||||
|
const handleTabVisible = () => {
|
||||||
|
console.log("Tab became visible, refreshing event requests...");
|
||||||
|
refreshEventRequests();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add event listener for custom dashboardTabVisible event
|
||||||
|
document.addEventListener("dashboardTabVisible", handleTabVisible);
|
||||||
|
|
||||||
|
// Clean up event listener on component unmount
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("dashboardTabVisible", handleTabVisible);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (filteredRequests.length === 0) {
|
if (filteredRequests.length === 0) {
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|
Loading…
Reference in a new issue