mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 21:20:56 +00:00
Prevent dashboard updates if tab not visible (#9924)
* Prevent dashboard updates if tab not visible * Uncomment code
This commit is contained in:
@ -9,6 +9,7 @@ import type { ModelType } from '@lib/enums/ModelType';
|
|||||||
import { apiUrl } from '@lib/functions/Api';
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
import { navigateToLink } from '@lib/functions/Navigation';
|
import { navigateToLink } from '@lib/functions/Navigation';
|
||||||
import type { InvenTreeIconType } from '@lib/types/Icons';
|
import type { InvenTreeIconType } from '@lib/types/Icons';
|
||||||
|
import { useDocumentVisibility } from '@mantine/hooks';
|
||||||
import { useApi } from '../../../contexts/ApiContext';
|
import { useApi } from '../../../contexts/ApiContext';
|
||||||
import { InvenTreeIcon } from '../../../functions/icons';
|
import { InvenTreeIcon } from '../../../functions/icons';
|
||||||
import { useUserState } from '../../../states/UserState';
|
import { useUserState } from '../../../states/UserState';
|
||||||
@ -32,15 +33,20 @@ function QueryCountWidget({
|
|||||||
const api = useApi();
|
const api = useApi();
|
||||||
const user = useUserState();
|
const user = useUserState();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const visibility = useDocumentVisibility();
|
||||||
|
|
||||||
const modelProperties = ModelInformationDict[modelType];
|
const modelProperties = ModelInformationDict[modelType];
|
||||||
|
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: ['dashboard-query-count', modelType, params],
|
queryKey: ['dashboard-query-count', modelType, params, visibility],
|
||||||
enabled: user.hasViewPermission(modelType),
|
enabled: user.hasViewPermission(modelType) && visibility === 'visible',
|
||||||
refetchOnMount: true,
|
refetchOnMount: true,
|
||||||
refetchInterval: 5 * 60 * 1000, // 5 minutes
|
refetchInterval: 10 * 60 * 1000, // 10 minute refetch interval
|
||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
|
if (visibility !== 'visible') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return api
|
return api
|
||||||
.get(apiUrl(modelProperties.api_endpoint), {
|
.get(apiUrl(modelProperties.api_endpoint), {
|
||||||
params: {
|
params: {
|
||||||
|
@ -59,7 +59,7 @@ export function Header() {
|
|||||||
{ open: openNotificationDrawer, close: closeNotificationDrawer }
|
{ open: openNotificationDrawer, close: closeNotificationDrawer }
|
||||||
] = useDisclosure(false);
|
] = useDisclosure(false);
|
||||||
|
|
||||||
const { isLoggedIn, isStaff } = useUserState();
|
const { isLoggedIn } = useUserState();
|
||||||
const [notificationCount, setNotificationCount] = useState<number>(0);
|
const [notificationCount, setNotificationCount] = useState<number>(0);
|
||||||
const globalSettings = useGlobalSettingsState();
|
const globalSettings = useGlobalSettingsState();
|
||||||
|
|
||||||
@ -71,10 +71,10 @@ export function Header() {
|
|||||||
|
|
||||||
// Fetch number of notifications for the current user
|
// Fetch number of notifications for the current user
|
||||||
const notifications = useQuery({
|
const notifications = useQuery({
|
||||||
queryKey: ['notification-count'],
|
queryKey: ['notification-count', visibility],
|
||||||
enabled: isLoggedIn() && visibility === 'visible',
|
enabled: isLoggedIn() && visibility === 'visible',
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn() || visibility != 'visible') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user