import { useEffect, useState } from "react"; import { ActivityIndicator, Alert, StyleSheet, Text, View } from "react-native"; import Screen from "../../layout/Screen"; import { Button, ButtonTray } from "../../UI/Button"; import Card from "../../UI/Card"; import useGlobalHook from "../../../hooks/useGlobalHook"; import { getSession } from "../../../hooks/SessionStore"; const GlobalCacheViewScreen = ({ navigation, route }) => { // Initialisations --------------------- const { cache, isFound: initIsFound, onFindLogged } = route.params; const { logFind } = useGlobalHook(); const session = getSession(); // State ------------------------------- const [isFound, setIsFound] = useState(initIsFound); const [isLogging, setIsLogging] = useState(false); // Handlers ---------------------------- const handleLogFind = async () => { if (!session.currentGlobalPlayerId) { Alert.alert( "Not joined", "You must join the event before logging a find.", ); return; } Alert.alert( "Log Discovery", `Record that you found "${cache.CacheName}" and earn ${cache.CachePoints ?? 0} points?`, [ { text: "Cancel", style: "cancel" }, { text: "Log Find", onPress: async () => { setIsLogging(true); const result = await logFind({ FindPlayerID: session.currentGlobalPlayerId, FindCacheID: cache.CacheID, FindDatetime: new Date().toISOString(), }); setIsLogging(false); if (result) { setIsFound(true); if (onFindLogged) onFindLogged(); Alert.alert( "Discovery logged!", `+${cache.CachePoints ?? 0} points earned.`, ); } else { Alert.alert("Error", "Could not log find. Please try again."); } }, }, ], ); }; // View -------------------------------- return ( {cache.CacheName} {isFound ? "Already Found" : "Not Yet Found"} Points {cache.CachePoints ?? 0} {cache.CacheDescription ? ( Description {cache.CacheDescription} ) : null} {cache.CacheClue ? ( Clue {cache.CacheClue} ) : null} {isLogging ? ( ) : ( {!isFound && (