From c629cf60745359c052f3dabea92f166dc7eed00c Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Thu, 9 Apr 2026 23:55:21 +0100 Subject: [PATCH] Update claiming logic in MapScreen and usePlayerGame to improve cache selection and visibility --- src/components/screens/MapScreen.js | 6 +++++- src/hooks/usePlayerGame.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/screens/MapScreen.js b/src/components/screens/MapScreen.js index afdd1b8..9c0c33d 100644 --- a/src/components/screens/MapScreen.js +++ b/src/components/screens/MapScreen.js @@ -442,6 +442,10 @@ const MapScreen = ({navigation, route}) => { const handleClaim = useCallback(async (cacheId) => { if (!session.currentGid) return; + if (!selectedCacheId || String(cacheId) !== String(selectedCacheId)) { + setIsClaiming(false); + return; + } const result = await claimCache({ gid: session.currentGid, cacheId, @@ -455,7 +459,7 @@ const MapScreen = ({navigation, route}) => { setTimeout(() => setClaimedPopupVisible(false), 3000); } await loadCaches(); - }, [session.currentGid, session.currentUid, session.currentTid, effectiveSGid, claimCache, setIsClaiming, loadCaches]); + }, [session.currentGid, session.currentUid, session.currentTid, effectiveSGid, selectedCacheId, claimCache, setIsClaiming, loadCaches]); const handleCreateCachePress = () => { const fallback = userLocation || {latitude: mapRegion.latitude, longitude: mapRegion.longitude}; diff --git a/src/hooks/usePlayerGame.js b/src/hooks/usePlayerGame.js index 56ec65e..b88e9a9 100644 --- a/src/hooks/usePlayerGame.js +++ b/src/hooks/usePlayerGame.js @@ -22,7 +22,7 @@ const usePlayerGame = (playerLocation, playerHeading, activeCaches, claimDistanc : null; let visible = selected && isInClaimCone(playerHeading, playerLocation, selected.coordinates, claimDistance); - if (!visible) { + if (!preferSelectedCache && !visible) { selected = caches.find((c) => isInClaimCone(playerHeading, playerLocation, c.coordinates, claimDistance)) || null; visible = Boolean(selected); }