diff --git a/frontend/src/components/RegionMap.tsx b/frontend/src/components/RegionMap.tsx index 22c8b83..2cd01c1 100644 --- a/frontend/src/components/RegionMap.tsx +++ b/frontend/src/components/RegionMap.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef, useCallback, useEffect } from 'react'; +import React, { useState, useRef, useCallback, useEffect, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { MapNode } from '@/components/MapNode'; import { SystemContextMenu } from '@/components/SystemContextMenu'; @@ -11,7 +11,7 @@ import { Header } from './Header'; import { ListCharacters, StartESILogin, SetDestinationForAll, PostRouteForAllByNames, GetCharacterLocations } from 'wailsjs/go/main/App'; import { toast } from '@/hooks/use-toast'; import { getSystemsRegions } from '@/utils/systemApi'; -import { useSystemJumps, useSystemKills } from '@/hooks/useSystemStatistics'; +import { useSystemJumps, useSystemKills, resolveSystemID } from '@/hooks/useSystemStatistics'; import { StatisticsToggle } from './StatisticsToggle'; // Interaction/indicator constants @@ -120,8 +120,9 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho const [showJumps, setShowJumps] = useState(false); const [showKills, setShowKills] = useState(false); - // Cache for system name to ID mappings + // System ID cache for statistics lookup const [systemIDCache, setSystemIDCache] = useState>(new Map()); + // New: selection/aim state for left-click aimbot behavior const [isSelecting, setIsSelecting] = useState(false); @@ -186,13 +187,29 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho const { data: killsData } = useSystemKills(showKills); useEffect(() => { - if (!isLoading && error == null && rsystems && rsystems.size > 0) + if (!isLoading && error == null && rsystems && rsystems.size > 0) { setSystems(rsystems); + + // Pre-resolve all system IDs for statistics lookup + const resolveSystemIDs = async () => { + const newCache = new Map(); + for (const systemName of rsystems.keys()) { + try { + const id = await resolveSystemID(systemName); + if (id) { + newCache.set(systemName, id); + } + } catch (error) { + console.warn(`Failed to resolve system ID for ${systemName}:`, error); + } + } + setSystemIDCache(newCache); + }; + + resolveSystemIDs(); + } }, [rsystems, isLoading, error]); - // For now, we'll use a simplified approach without system ID resolution - // The ESI data will be displayed for systems that have data, but we won't - // be able to match system names to IDs until the binding issue is resolved useEffect(() => { if (!systems || systems.size === 0) return; @@ -519,45 +536,50 @@ export const RegionMap = ({ regionName, focusSystem, isCompact = false, isWormho return nearestName; }; + // Create lookup maps for system statistics + const jumpsBySystemID = useMemo(() => { + if (!jumpsData) return new Map(); + const map = new Map(); + jumpsData.forEach(jump => { + map.set(jump.system_id, jump.ship_jumps); + }); + return map; + }, [jumpsData]); + + const killsBySystemID = useMemo(() => { + if (!killsData) return new Map(); + const map = new Map(); + killsData.forEach(kill => { + map.set(kill.system_id, kill.ship_kills); + }); + return map; + }, [killsData]); + // Helper functions to get statistics for a system const getSystemJumps = (systemName: string): number | undefined => { - if (!jumpsData || !showJumps) return undefined; + if (!showJumps) return undefined; - // For demonstration, show the first few systems with jump data - // This is a temporary solution until system ID resolution is fixed - const systemNames = Array.from(systems.keys()); - const systemIndex = systemNames.indexOf(systemName); + const systemID = systemIDCache.get(systemName); + if (!systemID) return undefined; - if (systemIndex >= 0 && systemIndex < jumpsData.length) { - const jumps = jumpsData[systemIndex].ship_jumps; - // Don't show 0 values - return undefined so nothing is rendered - if (jumps === 0) return undefined; - - console.log(`🚀 Found ${jumps} jumps for ${systemName} (using index ${systemIndex})`); - return jumps; - } + const jumps = jumpsBySystemID.get(systemID); + if (!jumps || jumps === 0) return undefined; - return undefined; + console.log(`🚀 Found ${jumps} jumps for ${systemName} (ID: ${systemID})`); + return jumps; }; const getSystemKills = (systemName: string): number | undefined => { - if (!killsData || !showKills) return undefined; + if (!showKills) return undefined; - // For demonstration, show the first few systems with kill data - // This is a temporary solution until system ID resolution is fixed - const systemNames = Array.from(systems.keys()); - const systemIndex = systemNames.indexOf(systemName); + const systemID = systemIDCache.get(systemName); + if (!systemID) return undefined; - if (systemIndex >= 0 && systemIndex < killsData.length) { - const kills = killsData[systemIndex].ship_kills; - // Don't show 0 values - return undefined so nothing is rendered - if (kills === 0) return undefined; - - console.log(`⚔️ Found ${kills} kills for ${systemName} (using index ${systemIndex})`); - return kills; - } + const kills = killsBySystemID.get(systemID); + if (!kills || kills === 0) return undefined; - return undefined; + console.log(`⚔️ Found ${kills} kills for ${systemName} (ID: ${systemID})`); + return kills; }; // Commit shift selection: toggle all systems within radius