feat(board): implement usePageActive hook to manage session refresh based on tab visibility

This commit is contained in:
Abhimanyu Saharan
2026-02-07 12:45:02 +05:30
parent f6e0a551e5
commit 3079a92492
4 changed files with 66 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ import { Button } from "@/components/ui/button";
import { createExponentialBackoff } from "@/lib/backoff";
import { apiDatetimeToMs, parseApiDatetime } from "@/lib/datetime";
import { cn } from "@/lib/utils";
import { usePageActive } from "@/hooks/usePageActive";
const SSE_RECONNECT_BACKOFF = {
baseMs: 1_000,
@@ -132,6 +133,7 @@ FeedCard.displayName = "FeedCard";
export default function ActivityPage() {
const { isSignedIn } = useAuth();
const isPageActive = usePageActive();
const feedQuery = useListTaskCommentFeedApiV1ActivityTaskCommentsGet<
listTaskCommentFeedApiV1ActivityTaskCommentsGetResponse,
@@ -189,6 +191,7 @@ export default function ActivityPage() {
}, []);
useEffect(() => {
if (!isPageActive) return;
if (!isSignedIn) return;
let isCancelled = false;
const abortController = new AbortController();
@@ -278,7 +281,7 @@ export default function ActivityPage() {
window.clearTimeout(reconnectTimeout);
}
};
}, [isSignedIn, pushFeedItem]);
}, [isPageActive, isSignedIn, pushFeedItem]);
const orderedFeed = useMemo(() => {
return [...feedItems].sort((a, b) => {