Add autoClaim feature to ClaimTimerView and adjust cache claiming logic in GlobalMapScreen

This commit is contained in:
bobbert committed 2026-04-09 23:06:57 +01:00
1 parent dc18186265
commit caf90d2d93
3 files changed
+30 -19

No files matched your search

+6 -1
View File
@@ -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 (
@@ -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}
/>
<ButtonTray>
@@ -385,7 +383,15 @@ const GlobalMapScreen = ({ navigation, route }) => {
onClick={handleOpenSelectedCache}
disabled={!selectedCacheId}
/>
<Button label="Leaderboard" onClick={handleGotoLeaderboard} />
<Button
label="Claim Cache"
onClick={() => {
if (claimTarget) {
handleClaim(claimTarget.id);
}
}}
disabled={!claimTarget || !session.currentGlobalPlayerId}
/>
<Button
label="Refresh"
onClick={() => loadData({ forceRefresh: true })}
+6 -6
View File
@@ -1,11 +1,11 @@
import { useCallback, useMemo } from "react";
import {useCallback, useMemo} from "react";
import API from "../components/API/API";
import globalApiConfig from "../components/API/api.json";
import {
clearGlobalDataCache,
clearGlobalDataCacheByPrefix,
getOrFetchGlobalData,
writeGlobalDataCache,
clearGlobalDataCache,
clearGlobalDataCacheByPrefix,
getOrFetchGlobalData,
writeGlobalDataCache,
} from "../utils/globalDataCache";
const GLOBAL_BASE = String(
@@ -303,7 +303,7 @@ const useGlobalHook = () => {
if (!isGlobalApiReady()) return null;
const response = await API.post(withKey(endpoints.finds), data);
if (!response.isSuccess) return null;
const find = unwrapSingle(response.result);
const find = unwrapSingle(response.result) || { ...data };
if (data?.FindPlayerID !== undefined && data?.FindPlayerID !== null) {
clearGlobalDataCache(CACHE_KEY.findsByPlayer(data.FindPlayerID));
}