Browse Source

Add auto-refresh pause

Pause automatic refresh while article modal is open and resume after closing, using a 5-minute interval. Implemented in src/pages/Index.tsx with useEffect watching isArticleModalOpen and refetch, ensuring no refresh during modal display.

X-Lovable-Edit-ID: edt-8b01e0d9-9284-45d1-9c01-8ff0e97b98b4
gpt-engineer-app[bot] 1 week ago
parent
commit
62a536bfaa
1 changed files with 16 additions and 0 deletions
  1. 16 0
      src/pages/Index.tsx

+ 16 - 0
src/pages/Index.tsx

@@ -115,6 +115,22 @@ const Index = () => {
       document.title = baseTitle;
     }
   }, [unreadCount]);
+
+  // Auto-refresh articles every 5 minutes, paused when article modal is open
+  const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes
+  useEffect(() => {
+    if (isArticleModalOpen) {
+      return;
+    }
+
+    const intervalId = setInterval(() => {
+      refetch();
+    }, REFRESH_INTERVAL);
+
+    return () => {
+      clearInterval(intervalId);
+    };
+  }, [isArticleModalOpen, refetch]);
   const handleRefresh = () => {
     refetch();
     toast.success("Flux actualisés");