import { useQuery } from '@tanstack/react-query'; import { RefreshCw } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { api } from '../api/client'; interface UsbCameraDevicePickerProps { printerName: string; /** The saved device path, '' when none is set. */ value: string; onSelect: (device: string) => void; onEnterManually: () => void; } /** Picks a USB camera from the video devices the server can see. */ export function UsbCameraDevicePicker({ printerName, value, onSelect, onEnterManually }: UsbCameraDevicePickerProps) { const { t } = useTranslation(); const { data, isLoading, isError, isFetching, refetch } = useQuery({ queryKey: ['usb-cameras'], queryFn: api.getUsbCameras, // A camera plugged in since the last look should show up on the next one. staleTime: 0, }); const cameras = data?.cameras ?? []; // A saved camera that is unplugged stays selected rather than being cleared. const missing = value !== '' && !isLoading && !cameras.some((camera) => camera.device === value); return (
{t('settings.usbCameraListFailed')}
} {data && cameras.length === 0 && (
{t('settings.usbCameraNoneFound')}{' '}
devices: - /dev/video0:/dev/video0