2024-12-11 18:35:36 +00:00
|
|
|
import { useGameRepairMutation, useGameResetMutation, useGameStartMutation, useGameStopMutation, useGameSwitchPlayerMutation } from '@/hooks/mutations/useGameMutation'
|
2024-12-10 17:56:50 +00:00
|
|
|
import { useAuth } from '@/hooks/useAuth'
|
2024-12-11 20:33:51 +00:00
|
|
|
import { useGame, useUpdateGameState } from '@/hooks/useGame'
|
2024-12-09 21:29:48 +00:00
|
|
|
import { useRouter } from 'expo-router'
|
2024-12-11 20:33:51 +00:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { Button, Dialog, FAB, List, Portal, Surface, Text } from 'react-native-paper'
|
2024-12-09 17:29:48 +00:00
|
|
|
|
|
|
|
export default function HistoryScreen() {
|
2024-12-09 21:29:48 +00:00
|
|
|
const router = useRouter()
|
2024-12-10 17:56:50 +00:00
|
|
|
const auth = useAuth()
|
2024-12-11 18:35:36 +00:00
|
|
|
const game = useGame()
|
2024-12-11 20:33:51 +00:00
|
|
|
const updateGameState = useUpdateGameState()
|
2024-12-11 18:35:36 +00:00
|
|
|
|
|
|
|
const gameStartMutation = useGameStartMutation({
|
|
|
|
auth,
|
2024-12-11 20:33:51 +00:00
|
|
|
updateGameState,
|
2024-12-11 18:35:36 +00:00
|
|
|
})
|
|
|
|
const gameStopMutation = useGameStopMutation({
|
|
|
|
auth,
|
2024-12-11 20:33:51 +00:00
|
|
|
updateGameState,
|
2024-12-11 18:35:36 +00:00
|
|
|
})
|
|
|
|
const gameSwitchMutation = useGameSwitchPlayerMutation({
|
|
|
|
auth,
|
2024-12-11 20:33:51 +00:00
|
|
|
updateGameState,
|
2024-12-11 18:35:36 +00:00
|
|
|
})
|
|
|
|
const gameRepairMutation = useGameRepairMutation({
|
|
|
|
auth,
|
2024-12-11 20:33:51 +00:00
|
|
|
updateGameState,
|
2024-12-11 18:35:36 +00:00
|
|
|
})
|
|
|
|
const gameResetMutation = useGameResetMutation({
|
|
|
|
auth,
|
2024-12-11 20:33:51 +00:00
|
|
|
updateGameState,
|
2024-12-11 18:35:36 +00:00
|
|
|
})
|
|
|
|
|
2024-12-11 20:33:51 +00:00
|
|
|
const [resetConfirmVisible, setResetConfirmVisible] = useState(false)
|
|
|
|
|
2024-12-09 17:29:48 +00:00
|
|
|
return (
|
2024-12-09 21:29:48 +00:00
|
|
|
<Surface
|
|
|
|
style={{ flex: 1 }}>
|
2024-12-11 18:35:36 +00:00
|
|
|
<List.Section title={"Paramètres"}>
|
|
|
|
<List.Item
|
|
|
|
key={"login"}
|
|
|
|
title="Connexion au serveur"
|
|
|
|
description={auth.loggedIn ? "Vous êtes déjà connecté⋅e" : "Vous n'êtes pas connecté⋅e"}
|
|
|
|
right={() => <FAB icon="login" size="small" onPress={() => router.navigate('/login')} />}
|
|
|
|
onPress={() => router.navigate('/login')} />
|
|
|
|
</List.Section>
|
|
|
|
<List.Section title={"Gestion du jeu"}>
|
|
|
|
<List.Item
|
|
|
|
key={"start"}
|
|
|
|
title="Démarrer le jeu"
|
|
|
|
disabled={game.gameStarted}
|
|
|
|
right={() => <FAB icon="play" size="small" disabled={game.gameStarted} />}
|
|
|
|
onPress={() => gameStartMutation.mutate()} />
|
|
|
|
<List.Item
|
|
|
|
key={"stop"}
|
|
|
|
title="Arrêter le jeu"
|
|
|
|
disabled={!game.gameStarted}
|
|
|
|
right={() => <FAB icon="stop" size="small" disabled={!game.gameStarted} />}
|
|
|
|
onPress={() => gameStopMutation.mutate()} />
|
|
|
|
<List.Item
|
|
|
|
key={"switch"}
|
|
|
|
title="Changer de joueur⋅se en course"
|
|
|
|
description="À utiliser après une capture"
|
|
|
|
disabled={!game.gameStarted}
|
|
|
|
right={() => <FAB icon="exit-run" size="small" disabled={!game.gameStarted} />}
|
|
|
|
onPress={() => gameSwitchMutation.mutate()} />
|
|
|
|
</List.Section>
|
|
|
|
<List.Section title={"Avancé"}>
|
|
|
|
<List.Item
|
|
|
|
key={"repair"}
|
|
|
|
title="Réparer"
|
|
|
|
description="Permet de réparer les soldes des joueur⋅ses à partir des défis réalisés et des trains emprunter. À manipuler avec précaution."
|
|
|
|
right={() => <FAB icon="reload-alert" size="small" variant={'tertiary'} />}
|
|
|
|
onPress={() => gameRepairMutation.mutate()} />
|
|
|
|
<List.Item
|
|
|
|
key={"reset"}
|
|
|
|
title="Réinitialiser les données de jeu"
|
|
|
|
description="Permet de détruire toutes les données. À manipuler avec précaution."
|
|
|
|
right={() => <FAB icon="reload-alert" size="small" variant={'tertiary'} />}
|
2024-12-11 20:33:51 +00:00
|
|
|
onPress={() => setResetConfirmVisible(true)} />
|
2024-12-11 18:35:36 +00:00
|
|
|
</List.Section>
|
2024-12-11 20:33:51 +00:00
|
|
|
<Portal>
|
|
|
|
<Dialog key="confirmReset" visible={resetConfirmVisible} onDismiss={() => setResetConfirmVisible(false)}>
|
|
|
|
<Dialog.Title>Confirmer</Dialog.Title>
|
|
|
|
<Dialog.Content>
|
|
|
|
<Text variant="bodyMedium">
|
|
|
|
Cette action va réinitialiser TOUTES les données de jeu : l'historique des positions, les défis réalisés et les trains empruntés.
|
|
|
|
Êtes-vous réellement sûr⋅e de vouloir tout supprimer ?
|
|
|
|
</Text>
|
|
|
|
</Dialog.Content>
|
|
|
|
<Dialog.Actions>
|
|
|
|
<Button onPress={() => setResetConfirmVisible(false)}>Annuler</Button>
|
|
|
|
<Button onPress={() => { setResetConfirmVisible(false); gameResetMutation.mutate() }}>Confirmer</Button>
|
|
|
|
</Dialog.Actions>
|
|
|
|
</Dialog>
|
|
|
|
</Portal>
|
2024-12-09 20:00:15 +00:00
|
|
|
</Surface>
|
2024-12-09 17:29:48 +00:00
|
|
|
)
|
|
|
|
}
|