diff --git a/client/app/(tabs)/challenges.tsx b/client/app/(tabs)/challenges.tsx
index 909b5d3..413f28d 100644
--- a/client/app/(tabs)/challenges.tsx
+++ b/client/app/(tabs)/challenges.tsx
@@ -39,13 +39,22 @@ function ChallengeScreenBody() {
}, [currentChallengeAction, challenges])
const [loading, setLoading] = useState(false)
const [successSnackbarVisible, setSuccessSnackbarVisible] = useState(false)
+ const [errorVisible, setErrorVisible] = useState(false)
+ const [error, setError] = useState([200, ""])
const drawRandomChallengeMutation = useDrawRandomChallengeMutation({
auth,
onPostSuccess: () => {
setLoading(true)
setSuccessSnackbarVisible(true)
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-challenges' || query.queryKey[0] === 'get-player' })
- }
+ },
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
const endChallenge = useEndChallenge({
auth,
@@ -54,6 +63,13 @@ function ChallengeScreenBody() {
setSuccessSnackbarVisible(true)
queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-challenges' || query.queryKey[0] === 'get-player' })
},
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
useEffect(() => {
if (challengeActions)
@@ -95,11 +111,23 @@ function ChallengeScreenBody() {
Vous êtes poursuiveuse, et n'avez donc pas de défi à accomplir.
setSuccessSnackbarVisible(false)}
- action={{ label: "Fermer", onPress: () => setSuccessSnackbarVisible(false) }}>
+ onIconPress={() => setSuccessSnackbarVisible(false)}>
Jeu actualisé
+ setErrorVisible(false)}
+ onIconPress={() => setErrorVisible(false)}>
+
+ Erreur {error[0]} : {error[1]}
+
+
>
}
diff --git a/client/app/(tabs)/settings.tsx b/client/app/(tabs)/settings.tsx
index 1f49527..1315630 100644
--- a/client/app/(tabs)/settings.tsx
+++ b/client/app/(tabs)/settings.tsx
@@ -1,12 +1,19 @@
import { useGameRepairMutation, useGameResetMutation, useGameStartMutation, useGameStopMutation, useGameSwitchPlayerMutation } from '@/hooks/mutations/useGameMutation'
import { useAuth } from '@/hooks/useAuth'
import { useGame, useUpdateGameState } from '@/hooks/useGame'
+import { useQueryClient } from '@tanstack/react-query'
import { useRouter } from 'expo-router'
import { useState } from 'react'
-import { Button, Dialog, FAB, List, Portal, Surface, Text } from 'react-native-paper'
+import { Button, Dialog, FAB, List, MD3Colors, Portal, Snackbar, Surface, Text } from 'react-native-paper'
export default function HistoryScreen() {
+ const [successVisible, setSuccessVisible] = useState(false)
+ const [successMessage, setSuccessMessage] = useState("")
+ const [errorVisible, setErrorVisible] = useState(false)
+ const [error, setError] = useState([200, ""])
+
const router = useRouter()
+ const queryClient = useQueryClient()
const auth = useAuth()
const game = useGame()
const updateGameState = useUpdateGameState()
@@ -14,22 +21,84 @@ export default function HistoryScreen() {
const gameStartMutation = useGameStartMutation({
auth,
updateGameState,
+ onPostSuccess: () => {
+ setSuccessVisible(true)
+ setSuccessMessage("Jeu démarré avec succès")
+ queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-game' })
+ },
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
const gameStopMutation = useGameStopMutation({
auth,
updateGameState,
+ onPostSuccess: () => {
+ setSuccessVisible(true)
+ setSuccessMessage("Jeu arrêté avec succès")
+ queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-game' })
+ },
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
const gameSwitchMutation = useGameSwitchPlayerMutation({
auth,
updateGameState,
+ onPostSuccess: () => {
+ setSuccessVisible(true)
+ setSuccessMessage("Échange de joueuse en course réalisé avec succès")
+ queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-game' })
+ },
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
const gameRepairMutation = useGameRepairMutation({
auth,
updateGameState,
+ onPostSuccess: () => {
+ setSuccessVisible(true)
+ setSuccessMessage("Réparation du jeu effectuée avec succès")
+ queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-game' })
+ queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'get-player' })
+ queryClient.invalidateQueries({ predicate: (query) => query.queryKey[0] === 'money-updates' })
+ },
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
const gameResetMutation = useGameResetMutation({
auth,
updateGameState,
+ onPostSuccess: () => {
+ setSuccessVisible(true)
+ setSuccessMessage("Jeu réinitialisé avec succès")
+ queryClient.invalidateQueries()
+ },
+ onError: ({ response, error }) => {
+ setErrorVisible(true)
+ if (response)
+ setError([response.statusCode, response.message])
+ else if (error)
+ setError([400, error.message])
+ },
})
const [resetConfirmVisible, setResetConfirmVisible] = useState(false)
@@ -80,6 +149,26 @@ export default function HistoryScreen() {
right={() => }
onPress={() => setResetConfirmVisible(true)} />
+ setSuccessVisible(false)}
+ onIconPress={() => setSuccessVisible(false)}>
+
+ {successMessage}
+
+
+ setErrorVisible(false)}
+ onIconPress={() => setErrorVisible(false)}>
+
+ Erreur {error[0]} : {error[1]}
+
+