From 06a53a9c856e7ed63010c27a36e295e2b94977d2 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 11 Jul 2023 18:14:23 +0800 Subject: [PATCH] feat: disable fetch activity when in background --- .../layout/header/internal/Activity.tsx | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/components/layout/header/internal/Activity.tsx b/src/components/layout/header/internal/Activity.tsx index 00792e32f3..61400c62c5 100644 --- a/src/components/layout/header/internal/Activity.tsx +++ b/src/components/layout/header/internal/Activity.tsx @@ -14,6 +14,7 @@ import { import { FloatPopover } from '~/components/ui/float-popover' import { softBouncePrest } from '~/constants/spring' import useDebounceValue from '~/hooks/common/use-debounce-value' +import { usePageIsActive } from '~/hooks/common/use-is-active' import { apiClient } from '~/lib/request' import { useAggregationSelector } from '~/providers/root/aggregation-data-provider' @@ -70,6 +71,7 @@ export const Activity = memo(() => { const activity = useActivity() + const isPageActive = usePageIsActive() const { data } = useQuery( ['activity'], async () => { @@ -83,7 +85,7 @@ export const Activity = memo(() => { }>() .then((res) => res) .catch((err: RequestError) => { - err.status === 404 && setIsEnabled(false) + setIsEnabled(false) return { processName: '', mediaInfo: undefined } }) }, @@ -91,7 +93,7 @@ export const Activity = memo(() => { refetchInterval: 1000 * 5 * 60, refetchOnMount: 'always', retry: false, - enabled: isEnabled, + enabled: isEnabled && isPageActive, meta: { persist: false, }, @@ -134,40 +136,42 @@ export const Activity = memo(() => { )} - - {!!appLabels[processName] && ( - - + {!!appLabels[processName] && ( + - {ownerName} 正在使用 {processName} - {appDescrption[processName] - ? ` ${appDescrption[processName]}` - : ''} - - - )} - + + {ownerName} 正在使用 {processName} + {appDescrption[processName] + ? ` ${appDescrption[processName]}` + : ''} + + + )} + + )} ) })