Skip to content

Commit

Permalink
✨ logic for quizz component
Browse files Browse the repository at this point in the history
  • Loading branch information
h-campos committed Apr 26, 2023
1 parent 3875540 commit 66d66b6
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/components/Quizz/Quizz.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
//Librairies
import React from 'react'
import uuid from 'react-uuid'

//Components
import { Answer } from '#/Answer'

//Data
import { quizzData } from '../../data/quizz-data'

//Store
import { usePaginationStore } from '../../hooks/usePagination'
import { useAnswerStore } from '../../hooks/useAnswer/useAnswer'

export const Quizz = () => {
const currentPage = usePaginationStore((state) => state.currentPage)
const nextPage = usePaginationStore((state) => state.nextPage)
const verifyAnswer = useAnswerStore((state) => state.verifyAnswer)

const getRightAnswer = (currentPage: number) => {
return quizzData[currentPage].answers.filter(
(answers) => answers.response === true
)[0].answer
}

return (
<div className='w-2/3 h-1/3 bg-zinc-300 rounded-md flex justify-between items-start flex-col p-6'>
<div>
<h4 className='text-xl mb-2'>
Comment faire un margin-top avec Tailwindcss ?
<div className='w-2/3 bg-zinc-300 rounded-md flex justify-between items-start flex-col p-6'>
<div className='mb-4'>
<h4 className='text-xl mb-2 font-semibold'>
{quizzData[currentPage].question}
</h4>
<span className='text-md'>
<span className='text-md text-gray-500'>
Choisis une réponse parmis les 4 ci-dessous.
</span>
</div>
<div className='w-full grid grid-cols-2 grid-rows-2 gap-2'>
<Answer />
<Answer />
<Answer />
<Answer />
<div className='w-full grid grid-cols-2 grid-rows-2 gap-2 mb-4'>
{quizzData[currentPage].answers.map(({ answer }) => {
return <Answer answer={answer} key={uuid()} />
})}
</div>
<button
onClick={() => {
verifyAnswer(getRightAnswer(currentPage), nextPage)
}}
className='py-3 px-4 bg-blue-300 rounded-md flex items-center justify-center gap-2 hover:bg-blue-400 transition ease-linear'
>
VALIDER
</button>
</div>
)
}

0 comments on commit 66d66b6

Please sign in to comment.