import { useQuery } from "@tanstack/react-query" import { devicesApi } from "@/services/devices" import { DeviceDto } from "@/types/device" import { useDeviceRegistration } from "@/contexts/device-registration-context" // Legacy hook for backward compatibility - prefer useDeviceRegistration context export function useDevices() { return useQuery({ queryKey: ["devices"], queryFn: () => devicesApi.getDevices(), staleTime: 0, // Always consider data stale to enable frequent refetching refetchInterval: 30 * 1000, // Refetch every 30 seconds refetchIntervalInBackground: true, // Continue polling when tab is not in focus }) } // Legacy hook for backward compatibility - prefer useDeviceRegistration context export function useDevicesList(): { devices: DeviceDto[] isLoading: boolean isError: boolean error: Error | null refetch: () => void } { const { data, isLoading, isError, error, refetch, } = useDevices() const devices = data?.devices ?? [] return { devices, isLoading, isError, error, refetch, } } // Enhanced hook that uses the device registration context export function useDeviceManagement() { const context = useDeviceRegistration() return { ...context, devices: context.state.registeredDevices, isLoading: context.state.isLoading, error: context.state.error, currentSession: context.state.currentSession, wsConnected: context.state.wsConnected, } }