mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-11 09:27:30 +00:00
fix(frontend): don't poll for updates when user not authorised
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { createContext, useContext, useState } from 'react'
|
import React, { createContext, useContext, useState } from 'react'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { versionAPI } from '../utils/api'
|
import { versionAPI, settingsAPI } from '../utils/api'
|
||||||
|
import { useAuth } from './AuthContext'
|
||||||
|
|
||||||
const UpdateNotificationContext = createContext()
|
const UpdateNotificationContext = createContext()
|
||||||
|
|
||||||
@@ -14,6 +15,15 @@ export const useUpdateNotification = () => {
|
|||||||
|
|
||||||
export const UpdateNotificationProvider = ({ children }) => {
|
export const UpdateNotificationProvider = ({ children }) => {
|
||||||
const [dismissed, setDismissed] = useState(false)
|
const [dismissed, setDismissed] = useState(false)
|
||||||
|
const { user, token } = useAuth()
|
||||||
|
|
||||||
|
// Ensure settings are loaded
|
||||||
|
const { data: settings, isLoading: settingsLoading } = useQuery({
|
||||||
|
queryKey: ['settings'],
|
||||||
|
queryFn: () => settingsAPI.get().then(res => res.data),
|
||||||
|
enabled: !!(user && token),
|
||||||
|
retry: 1
|
||||||
|
})
|
||||||
|
|
||||||
// Query for update information
|
// Query for update information
|
||||||
const { data: updateData, isLoading, error } = useQuery({
|
const { data: updateData, isLoading, error } = useQuery({
|
||||||
@@ -21,7 +31,8 @@ export const UpdateNotificationProvider = ({ children }) => {
|
|||||||
queryFn: () => versionAPI.checkUpdates().then(res => res.data),
|
queryFn: () => versionAPI.checkUpdates().then(res => res.data),
|
||||||
staleTime: 10 * 60 * 1000, // Data stays fresh for 10 minutes
|
staleTime: 10 * 60 * 1000, // Data stays fresh for 10 minutes
|
||||||
refetchOnWindowFocus: false, // Don't refetch when window regains focus
|
refetchOnWindowFocus: false, // Don't refetch when window regains focus
|
||||||
retry: 1
|
retry: 1,
|
||||||
|
enabled: !!(user && token && settings && !settingsLoading) // Only run when authenticated and settings are loaded
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateAvailable = updateData?.isUpdateAvailable && !dismissed
|
const updateAvailable = updateData?.isUpdateAvailable && !dismissed
|
||||||
|
|||||||
Reference in New Issue
Block a user