-
Notifications
You must be signed in to change notification settings - Fork 82
Feat: add quiz type circle image #2347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saadman30
wants to merge
17
commits into
4.0.0-dev
Choose a base branch
from
feat/quiz-type-circle-image
base: 4.0.0-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,163
−27
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
48a6682
feat: add draw image question type to quiz functionality
saadman30 263cb79
feat: enhance draw image question type functionality
saadman30 cf81225
fix: update label for draw image question type
saadman30 476f118
refactor: simplify answer processing for draw image question type
saadman30 3ecb33c
refactor: improve handling of draw image answer processing
saadman30 2a4c255
refactor: enhance draw image answer processing and security
saadman30 fc96b8c
refactor: clarify handling of local file URLs for draw image question…
saadman30 a16204d
refactor: migrate draw image mask handling to QuizModel
saadman30 90f8986
refactor: improve URL validation for draw image masks
saadman30 fd10003
refactor: enhance upload_base64_image method in Utils
saadman30 46a3c86
refactor: enhance draw image answer handling in Quiz and QuizModel
saadman30 ebb9640
refactor: improve draw image handling in Quiz and CourseModel
saadman30 0942d3f
refactor: optimize draw image URL resolution in QuizModel
saadman30 89743d7
refactor: enhance quiz attempt file path handling
saadman30 9bc088d
refactor: streamline DrawImage component and introduce FormDrawImage
saadman30 53131c7
refactor: update TutorDrawOnImage type definitions and clean up FormD…
saadman30 3aec3db
refactor: enhance FormDrawImage component to manage image replacement…
saadman30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
assets/src/js/v3/entries/course-builder/components/curriculum/question-types/DrawImage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { css } from '@emotion/react'; | ||
| import { useEffect } from 'react'; | ||
| import { Controller, useFieldArray, useFormContext } from 'react-hook-form'; | ||
|
|
||
| import { useQuizModalContext } from '@CourseBuilderContexts/QuizModalContext'; | ||
| import type { QuizForm } from '@CourseBuilderServices/quiz'; | ||
| import FormDrawImage from '@TutorShared/components/fields/quiz/questions/FormDrawImage'; | ||
| import { spacing } from '@TutorShared/config/styles'; | ||
| import { styleUtils } from '@TutorShared/utils/style-utils'; | ||
| import { QuizDataStatus, type QuizQuestionOption } from '@TutorShared/utils/types'; | ||
| import { nanoid } from '@TutorShared/utils/util'; | ||
|
|
||
| const DrawImage = () => { | ||
| const form = useFormContext<QuizForm>(); | ||
| const { activeQuestionId, activeQuestionIndex, validationError, setValidationError } = useQuizModalContext(); | ||
|
|
||
| const answersPath = `questions.${activeQuestionIndex}.question_answers` as 'questions.0.question_answers'; | ||
|
|
||
| const { fields: optionsFields } = useFieldArray({ | ||
| control: form.control, | ||
| name: answersPath, | ||
| }); | ||
|
|
||
| // Ensure there is always a single option for this question type. | ||
| useEffect(() => { | ||
| if (!activeQuestionId) { | ||
| return; | ||
| } | ||
| if (optionsFields.length > 0) { | ||
| return; | ||
| } | ||
| const baseAnswer: QuizQuestionOption = { | ||
| _data_status: QuizDataStatus.NEW, | ||
| is_saved: true, | ||
| answer_id: nanoid(), | ||
| belongs_question_id: activeQuestionId, | ||
| belongs_question_type: 'draw_image' as QuizQuestionOption['belongs_question_type'], | ||
| answer_title: '', | ||
| is_correct: '1', | ||
| image_id: undefined, | ||
| image_url: '', | ||
| answer_two_gap_match: '', | ||
| answer_view_format: 'draw_image', | ||
| answer_order: 0, | ||
| }; | ||
| form.setValue(answersPath, [baseAnswer]); | ||
| }, [activeQuestionId, optionsFields.length, answersPath, form]); | ||
|
|
||
| return ( | ||
| <div css={styles.optionWrapper}> | ||
| <Controller | ||
| key={optionsFields.length ? JSON.stringify(optionsFields[0]) : ''} | ||
| control={form.control} | ||
| name={`questions.${activeQuestionIndex}.question_answers.0` as 'questions.0.question_answers.0'} | ||
| render={(controllerProps) => ( | ||
| <FormDrawImage | ||
| {...controllerProps} | ||
| questionId={activeQuestionId} | ||
| validationError={validationError} | ||
| setValidationError={setValidationError} | ||
| /> | ||
| )} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DrawImage; | ||
|
|
||
| const styles = { | ||
| optionWrapper: css` | ||
| ${styleUtils.display.flex('column')}; | ||
| padding-left: ${spacing[40]}; | ||
| `, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_savedshould not betrueby default. It must be programmatically toggled totruewhen the user saves the question.