2024-12-12 18:33:44 +00:00
|
|
|
import ChallengeCard from '@/components/ChallengeCard'
|
2024-12-12 17:43:56 +00:00
|
|
|
import PenaltyBanner from '@/components/PenalyBanner'
|
2024-12-12 18:33:44 +00:00
|
|
|
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'
|
2024-12-01 17:58:53 +00:00
|
|
|
|
|
|
|
export default function ChallengesScreen() {
|
2024-12-12 18:33:44 +00:00
|
|
|
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])
|
|
|
|
|
2024-12-01 17:58:53 +00:00
|
|
|
return (
|
2024-12-12 17:01:08 +00:00
|
|
|
<Surface style={{ flex: 1 }}>
|
|
|
|
<Appbar.Header>
|
|
|
|
<Appbar.Content title={"Défis"} />
|
|
|
|
<Appbar.Action icon='format-list-bulleted' />
|
|
|
|
</Appbar.Header>
|
2024-12-12 17:43:56 +00:00
|
|
|
<PenaltyBanner />
|
2024-12-12 18:33:44 +00:00
|
|
|
{currentChallenge && <ChallengeCard challenge={currentChallenge} />}
|
2024-12-09 20:00:15 +00:00
|
|
|
</Surface>
|
2024-12-07 09:24:41 +00:00
|
|
|
)
|
2024-12-01 17:58:53 +00:00
|
|
|
}
|