// React import { useState, useEffect, Fragment } from 'react'; import { View, Text, Image, Alert, StyleSheet, TouchableOpacity } from 'react-native'; // Expo import { useRouter } from 'expo-router'; // Components import { CustomMap } from '../components/map'; import { Drawer } from '../components/drawer'; // Contexts import { useTeamConnexion } from '../context/teamConnexionContext'; import { useTeamContext } from '../context/teamContext'; // Hooks import { useGame } from '../hook/useGame'; import { useTimeDifference } from '../hook/useTimeDifference'; // Util import { GameState } from '../util/gameState'; import { TimerMMSS } from '../components/timer'; import { secondsToMMSS } from '../util/format'; import { Colors } from '../util/colors'; const Interface = () => { const router = useRouter(); const {messages, nextZoneDate, isShrinking, startLocationTracking, stopLocationTracking, gameState} = useTeamContext(); const {loggedIn, logout, loading} = useTeamConnexion(); const {name, ready, captured, locationSendDeadline, outOfZone, outOfZoneDeadline, hasHandicap, enemyHasHandicap} = useGame(); const [timeLeftSendLocation] = useTimeDifference(locationSendDeadline, 1000); const [timeLeftNextZone] = useTimeDifference(nextZoneDate, 1000); const [timeLeftOutOfZone] = useTimeDifference(outOfZoneDeadline, 1000); const [bottomContainerHeight, setBottomContainerHeight] = useState(0); // Router useEffect(() => { if (!loading) { if (!loggedIn) { router.replace("/"); } } }, [router, loggedIn, loading]); // Activating geolocation tracking useEffect(() => { if (loggedIn) { startLocationTracking(); } else { stopLocationTracking(); } }, [startLocationTracking, stopLocationTracking, loggedIn]); return ( Alert.alert("Settings")}> {(name ?? "Indisponible")} { gameState == GameState.SETUP && {messages?.waiting || "Préparation de la partie"}} { gameState == GameState.PLACEMENT && Phase de placement} { gameState == GameState.PLAYING && !outOfZone && La partie est en cours} { gameState == GameState.PLAYING && outOfZone && !hasHandicap && {`Veuillez retourner dans la zone\nHandicap dans ${secondsToMMSS(-timeLeftOutOfZone)}`}} { gameState == GameState.PLAYING && hasHandicap && {`Veuillez retourner dans la zone\nVotre position est révélée en continue`}} { gameState == GameState.FINISHED && La partie est terminée} { gameState == GameState.PLACEMENT && {ready ? "Placé" : "Non placé"} } { gameState == GameState.PLAYING && !captured && {enemyHasHandicap && Position ennemie révélée en continue ! } } { gameState == GameState.PLAYING && captured && {messages?.captured || "Vous avez été éliminé..."} } { gameState == GameState.FINISHED && {captured && {captured ? (messages?.loser || "Vous avez perdu...") : (messages?.winner || "Vous avez gagné !")}} } setBottomContainerHeight(event.nativeEvent.layout.height)}> ); }; export default Interface; const styles = StyleSheet.create({ globalContainer: { backgroundColor: Colors.background, flex: 1, }, topContainer: { width: '100%', alignItems: 'center', padding: 15, }, topheadContainer: { width: "100%", flexDirection: "row", justifyContent: 'space-between' }, teamNameContainer: { width: '100%', alignItems: 'center', justifyContent: 'center' }, logContainer: { width: '100%', alignItems: 'center', justifyContent: 'center', marginTop: 15 }, gameState: { borderWidth: 2, borderRadius: 10, width: "100%", backgroundColor: 'white', fontSize: 18, padding: 10, }, gameStateOutOfZone: { borderWidth: 2, borderRadius: 10, width: "100%", backgroundColor: 'white', fontSize: 18, padding: 10, borderColor: 'red' }, timersContainer: { width: '100%', alignItems: 'center', justifyContent: 'center', flexDirection: 'row', marginTop: 15 }, readyIndicator: { width: "100%", maxWidth: 240, height: 61, alignItems: 'center', justifyContent: 'center', padding: 3, borderRadius: 10 }, bottomContainer: { flex: 1, } });