import React, { useCallback } from 'react'; import type { BluetoothDevice, Action } from '../types.ts'; import { DeviceStatus } from '../types.ts'; import { DeviceCard } from './DeviceCard.tsx'; import { ScanIcon } from './icons.tsx'; interface DeviceScannerProps { devices: BluetoothDevice[]; onScan: () => void; dispatch: React.Dispatch; isScanning: boolean; } export const DeviceScanner: React.FC = ({ devices, onScan, dispatch, isScanning }) => { const handleConnect = useCallback((id: string) => { dispatch({ type: 'UPDATE_STATUS', payload: { id, status: DeviceStatus.Connecting } }); setTimeout(() => { const randomLatency = Math.floor(Math.random() * 50) + 5; dispatch({ type: 'UPDATE_STATUS', payload: { id, status: DeviceStatus.Connected, latency: randomLatency } }); }, 1500); }, [dispatch]); return (

Available Devices

{isScanning && devices.length === 0 && (

Searching for nearby devices...

)} {!isScanning && devices.length === 0 && (

No devices found. Try scanning again.

)} {devices.map(device => ( ))}
); };