diff --git a/client/app/(tabs)/challenges.tsx b/client/app/(tabs)/challenges.tsx index c1c3ed8..5369242 100644 --- a/client/app/(tabs)/challenges.tsx +++ b/client/app/(tabs)/challenges.tsx @@ -1,9 +1,26 @@ +import ChallengeCard from '@/components/ChallengeCard' import PenaltyBanner from '@/components/PenalyBanner' -import { FontAwesome6 } from '@expo/vector-icons' -import { View } from 'react-native' -import { Appbar, Button, Surface, Text } from 'react-native-paper' +import { useChallengeActions } from '@/hooks/useChallengeActions' +import { useChallenges } from '@/hooks/useChallenges' +import { useGame } from '@/hooks/useGame' +import { useMemo } from 'react' +import { Appbar, Surface } from 'react-native-paper' export default function ChallengesScreen() { + const game = useGame() + const challengeActions = useChallengeActions() + const challenges = useChallenges() + const currentChallengeAction = useMemo(() => { + if (!game.currentChallengeId) + return null + return challengeActions.challengeActions.find((action) => action.id === game.currentChallengeId) + }, [game, challengeActions]) + const currentChallenge = useMemo(() => { + if (!currentChallengeAction) + return null + return challenges.challenges.find((challenge) => challenge.id === currentChallengeAction.challengeId) + }, [currentChallengeAction, challenges]) + return ( @@ -11,27 +28,7 @@ export default function ChallengesScreen() { - - - Titre - - - - Description - - Récompense : 500 - - - - - - - - + {currentChallenge && } ) } diff --git a/client/components/ChallengeCard.tsx b/client/components/ChallengeCard.tsx new file mode 100644 index 0000000..e03fb8c --- /dev/null +++ b/client/components/ChallengeCard.tsx @@ -0,0 +1,30 @@ +import { Challenge } from "@/utils/features/challenges/challengesSlice" +import { FontAwesome6 } from "@expo/vector-icons" +import { View } from "react-native" +import { Button, Surface, Text } from "react-native-paper" + +export default function ChallengeCard({ challenge }: { challenge: Challenge }) { + return ( + + + {challenge.title} + + + + {challenge.description} + + Récompense : {challenge.reward} + + + + + + + + + ) +} \ No newline at end of file diff --git a/client/hooks/useChallenges.ts b/client/hooks/useChallenges.ts index 9dcd5e9..c4b6605 100644 --- a/client/hooks/useChallenges.ts +++ b/client/hooks/useChallenges.ts @@ -1,3 +1,3 @@ import { useAppSelector } from "./useStore" -export const useTrain = () => useAppSelector((state) => state.challenges) +export const useChallenges = () => useAppSelector((state) => state.challenges) diff --git a/client/utils/features/game/gameSlice.ts b/client/utils/features/game/gameSlice.ts index f24684d..bd0531c 100644 --- a/client/utils/features/game/gameSlice.ts +++ b/client/utils/features/game/gameSlice.ts @@ -1,4 +1,5 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' +import { ChallengeAction } from '../challengeActions/challengeActionsSlice' export interface RunPayload { id: number @@ -20,9 +21,10 @@ export interface GameState { gameStarted: boolean money: number currentRunner: boolean + currentChallengeId: number | null chaseFreeTime: number | null // date penaltyStart: number | null // date - penaltyEnd: number | null // date + penaltyEnd: number | null //date } const initialState: GameState = { @@ -30,6 +32,7 @@ const initialState: GameState = { gameStarted: false, money: 0, currentRunner: false, + currentChallengeId: null, chaseFreeTime: null, penaltyStart: null, penaltyEnd: null,