Skip to content

Commit

Permalink
feat: quiz question image
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoEscaleira committed Mar 20, 2024
1 parent e55eab2 commit 658b40f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/components/Quiz/QuestionsFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export function QuestionFields() {
/>
</div>

<div className="mb-2">
<FormInput
name={`questions.${questionIndex}.image`}
size="md"
label="Image"
fieldError={errors.questions?.[questionIndex]?.image}
/>
</div>

<Select
label="Type"
value={getValues(`questions.${questionIndex}.type`)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Quiz/quizFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const quizFormSchema = z
correct: z.boolean(),
})
),
image: z.string().optional(),
})
),
difficulty: z.nativeEnum(Difficulty),
Expand Down
6 changes: 6 additions & 0 deletions src/components/QuizAttempt/QuizAttempt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export function QuizAttempt({ quiz }: QuizAttemptProps) {
{question.question}
</Typography>

{question.image && (
<div className="mt-6 flex w-full justify-center">
<img src={question.image} alt="question figure" className="size-[300px]" />
</div>
)}

<div className="mt-10 flex flex-wrap gap-5 sm:gap-7">
{question.options.map(({ text, chosen }) => (
<Button
Expand Down
1 change: 1 addition & 0 deletions src/utils/queries/QuizById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const GET_QUIZ_BY_ID = gql(/* GraphQL */ `
questions {
question
type
image
options {
correct
text
Expand Down

0 comments on commit 658b40f

Please sign in to comment.