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
+25 -14

No files matched your search

+6 -1
View File
@@ -9,6 +9,7 @@ const ClaimTimerView = ({
showClaimedPopup, showClaimedPopup,
claimDurationSeconds = CACHE_CLAIM_TIMER, claimDurationSeconds = CACHE_CLAIM_TIMER,
claimedPopupMessage = 'Cache Claimed!', claimedPopupMessage = 'Cache Claimed!',
autoClaim = true,
}) => { }) => {
const [timeLeft, setTimeLeft] = useState(claimDurationSeconds); const [timeLeft, setTimeLeft] = useState(claimDurationSeconds);
const onClaimRef = useRef(onClaimSuccess); const onClaimRef = useRef(onClaimSuccess);
@@ -31,6 +32,10 @@ const ClaimTimerView = ({
return () => clearTimeout(timer); return () => clearTimeout(timer);
} }
if (!autoClaim) {
return () => clearTimeout(timer);
}
if (claimDurationSeconds <= 0) { if (claimDurationSeconds <= 0) {
if (!hasClaimedRef.current) { if (!hasClaimedRef.current) {
hasClaimedRef.current = true; hasClaimedRef.current = true;
@@ -47,7 +52,7 @@ const ClaimTimerView = ({
} }
return () => clearTimeout(timer); return () => clearTimeout(timer);
}, [claimDurationSeconds, cache, isClaiming, timeLeft]); }, [autoClaim, claimDurationSeconds, cache, isClaiming, timeLeft]);
if (showClaimedPopup) { if (showClaimedPopup) {
return ( return (
@@ -19,7 +19,7 @@ const DEFAULT_REGION = {
longitudeDelta: 0.05, longitudeDelta: 0.05,
}; };
const GLOBAL_CLAIM_DISTANCE_METERS = 50; const GLOBAL_CLAIM_DISTANCE_METERS = 30;
const GlobalMapScreen = ({ navigation, route }) => { const GlobalMapScreen = ({ navigation, route }) => {
// Initialisations --------------------- // Initialisations ---------------------
@@ -114,7 +114,9 @@ const GlobalMapScreen = ({ navigation, route }) => {
return; return;
} }
const alreadyFound = foundCacheIds.includes(cacheId); const alreadyFound = foundCacheIds.some(
(id) => String(id) === String(cacheId),
);
if (alreadyFound) { if (alreadyFound) {
setIsClaiming(false); setIsClaiming(false);
return; return;
@@ -134,15 +136,14 @@ const GlobalMapScreen = ({ navigation, route }) => {
if (result) { if (result) {
const cacheName = claimedCache?.CacheName || "Cache"; const cacheName = claimedCache?.CacheName || "Cache";
setFoundCacheIds((prev) => const points = Number(claimedCache?.CachePoints ?? 0);
prev.includes(cacheId) ? prev : [...prev, cacheId], setClaimedPopupMessage(`${cacheName} claimed! You gained +${points} points.`);
);
setClaimedPopupMessage(`${cacheName} claimed! You gained +10 points.`);
setClaimedPopupVisible(true); setClaimedPopupVisible(true);
setTimeout(() => setClaimedPopupVisible(false), 3000); setTimeout(() => setClaimedPopupVisible(false), 3000);
await loadData({ forceRefresh: true });
} }
}, },
[caches, foundCacheIds, session.currentGlobalPlayerId, setIsClaiming], [caches, foundCacheIds, loadData, session.currentGlobalPlayerId, setIsClaiming],
); );
const handleCacheSelect = (cache) => { const handleCacheSelect = (cache) => {
@@ -163,10 +164,6 @@ const GlobalMapScreen = ({ navigation, route }) => {
}); });
}; };
const handleGotoLeaderboard = () => {
navigation.navigate("GlobalLeaderboardScreen", { eventId });
};
useEffect(() => { useEffect(() => {
if (session.isBusiness || session.currentGameMode !== GAME_MODE.GLOBAL) { if (session.isBusiness || session.currentGameMode !== GAME_MODE.GLOBAL) {
navigation.replace("MapScreen"); navigation.replace("MapScreen");
@@ -377,6 +374,7 @@ const GlobalMapScreen = ({ navigation, route }) => {
showClaimedPopup={claimedPopupVisible} showClaimedPopup={claimedPopupVisible}
claimDurationSeconds={0} claimDurationSeconds={0}
claimedPopupMessage={claimedPopupMessage} claimedPopupMessage={claimedPopupMessage}
autoClaim={false}
/> />
<ButtonTray> <ButtonTray>
@@ -385,7 +383,15 @@ const GlobalMapScreen = ({ navigation, route }) => {
onClick={handleOpenSelectedCache} onClick={handleOpenSelectedCache}
disabled={!selectedCacheId} disabled={!selectedCacheId}
/> />
<Button label="Leaderboard" onClick={handleGotoLeaderboard} /> <Button
label="Claim Cache"
onClick={() => {
if (claimTarget) {
handleClaim(claimTarget.id);
}
}}
disabled={!claimTarget || !session.currentGlobalPlayerId}
/>
<Button <Button
label="Refresh" label="Refresh"
onClick={() => loadData({ forceRefresh: true })} onClick={() => loadData({ forceRefresh: true })}
+1 -1
View File
@@ -303,7 +303,7 @@ const useGlobalHook = () => {
if (!isGlobalApiReady()) return null; if (!isGlobalApiReady()) return null;
const response = await API.post(withKey(endpoints.finds), data); const response = await API.post(withKey(endpoints.finds), data);
if (!response.isSuccess) return null; if (!response.isSuccess) return null;
const find = unwrapSingle(response.result); const find = unwrapSingle(response.result) || { ...data };
if (data?.FindPlayerID !== undefined && data?.FindPlayerID !== null) { if (data?.FindPlayerID !== undefined && data?.FindPlayerID !== null) {
clearGlobalDataCache(CACHE_KEY.findsByPlayer(data.FindPlayerID)); clearGlobalDataCache(CACHE_KEY.findsByPlayer(data.FindPlayerID));
} }