diff --git a/src/components/SystemTracker.tsx b/src/components/SystemTracker.tsx index 998d2d6..4a0b85d 100644 --- a/src/components/SystemTracker.tsx +++ b/src/components/SystemTracker.tsx @@ -6,7 +6,6 @@ import { Button } from "@/components/ui/button"; import { RefreshCw, AlertCircle, Radar } from "lucide-react"; import SignatureListItem from "./SignatureListItem"; import { toast } from "@/hooks/use-toast"; -import { useNavigate } from "react-router-dom"; interface SignatureItem { collectionId: string; @@ -27,45 +26,27 @@ interface ApiResponse { } interface SystemTrackerProps { - initialSystem?: string; + system: string; } -const SystemTracker = ({ initialSystem }: SystemTrackerProps) => { - const [currentSystem, setCurrentSystem] = useState(initialSystem || ""); - const navigate = useNavigate(); - - // Query to get current system from localhost:7000 (always enabled to track system changes) - const { data: systemData, refetch: refetchSystem, isLoading: systemLoading } = useQuery({ - queryKey: ['currentSystem'], - queryFn: async () => { - const response = await fetch('http://localhost:7000'); - if (!response.ok) { - throw new Error('Failed to fetch current system'); - } - const text = await response.text(); - return text.trim(); - }, - refetchInterval: 1000, // Always refetch to track system changes - retry: 3, - }); - +const SystemTracker = ({ system }: SystemTrackerProps) => { // Query to get signatures for the current system - const { - data: signaturesData, - refetch: refetchSignatures, + const { + data: signaturesData, + refetch: refetchSignatures, isLoading: signaturesLoading, - error: signaturesError + error: signaturesError } = useQuery({ - queryKey: ['signatures', currentSystem], + queryKey: ['signatures', system], queryFn: async () => { - if (!currentSystem) return null; - - const encodedSystem = encodeURIComponent(currentSystem); + if (!system) return null; + + const encodedSystem = encodeURIComponent(system); const url = `https://evebase.site.quack-lab.dev/api/collections/sigview/records?filter=(system%3D'${encodedSystem}')`; - - console.log('Fetching signatures for system:', currentSystem); + + console.log('Fetching signatures for system:', system); console.log('API URL:', url); - + const response = await fetch(url); if (!response.ok) { throw new Error('Failed to fetch signatures'); @@ -73,41 +54,26 @@ const SystemTracker = ({ initialSystem }: SystemTrackerProps) => { const data: ApiResponse = await response.json(); return data; }, - enabled: !!currentSystem, + enabled: !!system, refetchInterval: 60000, // Keep signature refresh at 1 minute }); - // Update current system when data changes and navigate to new system - useEffect(() => { - if (systemData && systemData !== currentSystem) { - setCurrentSystem(systemData); - navigate(`/${systemData}`); - console.log('Current system updated to:', systemData); - // Immediately refetch signatures when system changes - refetchSignatures(); - toast({ - title: "System Updated", - description: `Now tracking: ${systemData}`, - }); - } - }, [systemData, currentSystem, refetchSignatures, navigate]); - // Refresh signatures every 5 seconds useEffect(() => { const refreshInterval = setInterval(() => { console.log('Auto-refreshing signatures...'); - if (currentSystem) { + if (system) { refetchSignatures(); } }, 5000); // Cleanup interval on component unmount return () => clearInterval(refreshInterval); - }, [refetchSignatures, currentSystem]); + }, [refetchSignatures, system]); const handleRefresh = () => { - refetchSystem(); - if (currentSystem) { + refetchSignatures(); + if (system) { refetchSignatures(); } toast({ @@ -117,7 +83,7 @@ const SystemTracker = ({ initialSystem }: SystemTrackerProps) => { }; const signatures = signaturesData?.items || []; - const isLoading = systemLoading || signaturesLoading; + const isLoading = signaturesLoading; // Sort signatures by date (newest first) and prioritize unknown types const sortedSignatures = [...signatures].sort((a, b) => { @@ -126,12 +92,12 @@ const SystemTracker = ({ initialSystem }: SystemTrackerProps) => { const bIsUnknown = !b.type || b.type === ''; if (aIsUnknown && !bIsUnknown) return -1; if (!aIsUnknown && bIsUnknown) return 1; - + // If both are unknown or both are known, sort by type if (a.type !== b.type) { return a.type.localeCompare(b.type); } - + // If same type, sort by date const dateA = a.updated || a.created || ''; const dateB = b.updated || b.created || ''; @@ -153,10 +119,10 @@ const SystemTracker = ({ initialSystem }: SystemTrackerProps) => { - {initialSystem ? 'System View' : 'Current System'} + {system} -