import React, { useState, useEffect } from 'react'; import api from '../services/api'; import { format } from 'date-fns'; import { t } from '../utils/tempTranslations'; // Temporary translation system import { MagnifyingGlassIcon, FunnelIcon, EyeIcon } from '@heroicons/react/24/outline'; const Detections = () => { const [detections, setDetections] = useState([]); const [loading, setLoading] = useState(true); const [pagination, setPagination] = useState({}); const [filters, setFilters] = useState({ device_id: '', drone_id: '', start_date: '', end_date: '', limit: 50, offset: 0 }); const [showFilters, setShowFilters] = useState(false); useEffect(() => { fetchDetections(); }, [filters]); const fetchDetections = async () => { try { setLoading(true); const params = new URLSearchParams(); Object.entries(filters).forEach(([key, value]) => { if (value) params.append(key, value); }); console.log('🔍 Fetching detections with params:', params.toString()); const response = await api.get(`/detections?${params}`); console.log('✅ Detections response:', response.data); setDetections(response.data.data?.detections || []); setPagination(response.data.data?.pagination || {}); } catch (error) { console.error('❌ Error fetching detections:', error); setDetections([]); // Ensure detections is always an array setPagination({}); } finally { setLoading(false); } }; const handleFilterChange = (key, value) => { setFilters(prev => ({ ...prev, [key]: value, offset: 0 // Reset to first page when filtering })); }; const handlePageChange = (newOffset) => { setFilters(prev => ({ ...prev, offset: newOffset })); }; const clearFilters = () => { setFilters({ device_id: '', drone_id: '', start_date: '', end_date: '', limit: 50, offset: 0 }); }; return (
History of all drone detections from your devices
| Device | Drone ID | Type | Frequency | RSSI | Location | Detected At | Actions |
|---|---|---|---|---|---|---|---|
|
{detection.device?.name || `Device ${detection.device_id}`}
ID: {detection.device_id}
|
{detection.drone_id} |
{detection.drone_type_info?.name || `Type ${detection.drone_type}`}
{detection.drone_type_info?.category && (
{detection.drone_type_info.category}
)}
|
{detection.freq} MHz | -60 ? 'text-red-600' : detection.rssi > -80 ? 'text-yellow-600' : 'text-green-600' }`}> {detection.rssi} dBm |
{detection.device?.location_description ||
(detection.geo_lat && detection.geo_lon ?
`${detection.geo_lat}, ${detection.geo_lon}` :
'Unknown')}
|
{format(new Date(detection.server_timestamp), 'MMM dd, yyyy')}
{format(new Date(detection.server_timestamp), 'HH:mm:ss')}
|
Try adjusting your search filters.
Showing{' '} {filters.offset + 1} {' '}to{' '} {Math.min(filters.offset + filters.limit, pagination.total)} {' '}of{' '} {pagination.total} {' '}results