From 972b7e351bd07db7eb3d2f2e7c82e28fb402ebe5 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Wed, 10 Jul 2024 00:22:48 +0700 Subject: [PATCH] Refetch using manual visibility change --- src/modules/chat/HomePage/ChatContent.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/modules/chat/HomePage/ChatContent.tsx b/src/modules/chat/HomePage/ChatContent.tsx index 5e49b7299..196a188f0 100644 --- a/src/modules/chat/HomePage/ChatContent.tsx +++ b/src/modules/chat/HomePage/ChatContent.tsx @@ -273,11 +273,21 @@ function PostMemeButton({ const myAddress = useMyMainAddress() ?? '' const { data, isLoading } = getBalanceQuery.useQuery(myAddress) - const { data: timeLeftFromApi, isLoading: loadingTimeLeft } = - getTimeLeftUntilCanPostQuery.useQuery(myAddress, { - refetchOnWindowFocus: true, - staleTime: 0, - }) + + const { + data: timeLeftFromApi, + isLoading: loadingTimeLeft, + refetch, + } = getTimeLeftUntilCanPostQuery.useQuery(myAddress) + useEffect(() => { + const listener = () => { + if (document.visibilityState === 'visible') refetch() + } + document.addEventListener('visibilitychange', listener, false) + return () => { + document.removeEventListener('visibilitychange', listener) + } + }, [refetch]) const { threshold, isLoading: loadingThreshold } = usePostMemeThreshold(chatId)