From caf90d2d9323d458bb0b70254b08db7a6e10eee5 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Thu, 9 Apr 2026 23:06:57 +0100 Subject: [PATCH] Add autoClaim feature to ClaimTimerView and adjust cache claiming logic in GlobalMapScreen --- src/components/gameplay/ClaimTimerView.js | 7 ++++- .../screens/global/GlobalMapScreen.js | 30 +++++++++++-------- src/hooks/useGlobalHook.js | 12 ++++---- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/components/gameplay/ClaimTimerView.js b/src/components/gameplay/ClaimTimerView.js index f390a46..1c52826 100644 --- a/src/components/gameplay/ClaimTimerView.js +++ b/src/components/gameplay/ClaimTimerView.js @@ -9,6 +9,7 @@ const ClaimTimerView = ({ showClaimedPopup, claimDurationSeconds = CACHE_CLAIM_TIMER, claimedPopupMessage = 'Cache Claimed!', + autoClaim = true, }) => { const [timeLeft, setTimeLeft] = useState(claimDurationSeconds); const onClaimRef = useRef(onClaimSuccess); @@ -31,6 +32,10 @@ const ClaimTimerView = ({ return () => clearTimeout(timer); } + if (!autoClaim) { + return () => clearTimeout(timer); + } + if (claimDurationSeconds <= 0) { if (!hasClaimedRef.current) { hasClaimedRef.current = true; @@ -47,7 +52,7 @@ const ClaimTimerView = ({ } return () => clearTimeout(timer); - }, [claimDurationSeconds, cache, isClaiming, timeLeft]); + }, [autoClaim, claimDurationSeconds, cache, isClaiming, timeLeft]); if (showClaimedPopup) { return ( diff --git a/src/components/screens/global/GlobalMapScreen.js b/src/components/screens/global/GlobalMapScreen.js index c29fcd9..4db40d9 100644 --- a/src/components/screens/global/GlobalMapScreen.js +++ b/src/components/screens/global/GlobalMapScreen.js @@ -19,7 +19,7 @@ const DEFAULT_REGION = { longitudeDelta: 0.05, }; -const GLOBAL_CLAIM_DISTANCE_METERS = 50; +const GLOBAL_CLAIM_DISTANCE_METERS = 30; const GlobalMapScreen = ({ navigation, route }) => { // Initialisations --------------------- @@ -114,7 +114,9 @@ const GlobalMapScreen = ({ navigation, route }) => { return; } - const alreadyFound = foundCacheIds.includes(cacheId); + const alreadyFound = foundCacheIds.some( + (id) => String(id) === String(cacheId), + ); if (alreadyFound) { setIsClaiming(false); return; @@ -134,15 +136,14 @@ const GlobalMapScreen = ({ navigation, route }) => { if (result) { const cacheName = claimedCache?.CacheName || "Cache"; - setFoundCacheIds((prev) => - prev.includes(cacheId) ? prev : [...prev, cacheId], - ); - setClaimedPopupMessage(`${cacheName} claimed! You gained +10 points.`); + const points = Number(claimedCache?.CachePoints ?? 0); + setClaimedPopupMessage(`${cacheName} claimed! You gained +${points} points.`); setClaimedPopupVisible(true); setTimeout(() => setClaimedPopupVisible(false), 3000); + await loadData({ forceRefresh: true }); } }, - [caches, foundCacheIds, session.currentGlobalPlayerId, setIsClaiming], + [caches, foundCacheIds, loadData, session.currentGlobalPlayerId, setIsClaiming], ); const handleCacheSelect = (cache) => { @@ -163,10 +164,6 @@ const GlobalMapScreen = ({ navigation, route }) => { }); }; - const handleGotoLeaderboard = () => { - navigation.navigate("GlobalLeaderboardScreen", { eventId }); - }; - useEffect(() => { if (session.isBusiness || session.currentGameMode !== GAME_MODE.GLOBAL) { navigation.replace("MapScreen"); @@ -377,6 +374,7 @@ const GlobalMapScreen = ({ navigation, route }) => { showClaimedPopup={claimedPopupVisible} claimDurationSeconds={0} claimedPopupMessage={claimedPopupMessage} + autoClaim={false} /> @@ -385,7 +383,15 @@ const GlobalMapScreen = ({ navigation, route }) => { onClick={handleOpenSelectedCache} disabled={!selectedCacheId} /> -