-
Notifications
You must be signed in to change notification settings - Fork 4
No ref/new prop to jump to question #251
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
Changes from 15 commits
dd5ccc0
1db8d1f
1ee8c11
a123045
1475a7f
414255e
16b25cc
c390b16
ccdd2b5
e4e734b
e198dd6
4bf09ab
cf31952
bdfb096
320e8b8
547d1d4
e835cc7
e62ca24
a9419aa
a2fe67b
2c2ce04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { useCallback } from 'react'; | ||
| import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer'; | ||
| import { GetJumpToQuestionButtonProps, QuizEventsReturn } from '../../types'; | ||
|
|
||
| export default function useNextQuestionButtonProps( | ||
TarekAlQaddy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| jumpToQuestion: QuizEventsReturn.JumpToQuestion, | ||
| quizApiState: QuizAPIReducerState | ||
| ): GetJumpToQuestionButtonProps { | ||
| const getJumpToQuestionButtonProps: GetJumpToQuestionButtonProps = useCallback( | ||
| (id: number) => { | ||
| const currentQuestionId = quizApiState.quizCurrentQuestion?.next_question?.id; | ||
| let buttonDisabled; | ||
| if (!currentQuestionId || (currentQuestionId && id >= currentQuestionId)) { | ||
TarekAlQaddy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| buttonDisabled = true; | ||
| } | ||
|
|
||
| return { | ||
| className: buttonDisabled ? 'cio-question-cta-button disabled' : 'cio-question-cta-button', | ||
| tabIndex: buttonDisabled ? -1 : 0, | ||
| 'aria-disabled': buttonDisabled ? 'true' : 'false', | ||
| 'aria-describedby': buttonDisabled ? 'jump-to-button-help' : '', | ||
| type: 'button', | ||
|
Comment on lines
19
to
22
|
||
| onClick: () => { | ||
| jumpToQuestion(id); | ||
| }, | ||
| }; | ||
| }, | ||
| [quizApiState.quizCurrentQuestion, jumpToQuestion] | ||
| ); | ||
|
|
||
| return getJumpToQuestionButtonProps; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { useCallback } from 'react'; | ||
| import { | ||
| ActionAnswerQuestion, | ||
| ActionQuizAPI, | ||
| QuestionTypes, | ||
| QuizAPIActionTypes, | ||
| } from '../../components/CioQuiz/actions'; | ||
| import { QuizEventsReturn } from '../../types'; | ||
| import { QuizAPIReducerState } from '../../components/CioQuiz/quizApiReducer'; | ||
| import { QuizLocalReducerState } from '../../components/CioQuiz/quizLocalReducer'; | ||
|
|
||
| type IUseJumpToQuestionProps = { | ||
| dispatchLocalState: React.Dispatch<ActionAnswerQuestion>; | ||
| dispatchApiState: React.Dispatch<ActionQuizAPI>; | ||
| quizApiState: QuizAPIReducerState; | ||
| quizLocalState: QuizLocalReducerState; | ||
| }; | ||
|
|
||
| const useJumpToQuestion = (props: IUseJumpToQuestionProps): QuizEventsReturn.JumpToQuestion => { | ||
| const { dispatchLocalState, dispatchApiState, quizApiState, quizLocalState } = props; | ||
| const quizResetClickHandler = useCallback( | ||
TarekAlQaddy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (questionId: number) => { | ||
| const isComplete = quizLocalState.isQuizCompleted; | ||
| const currentQuestionId = quizApiState.quizCurrentQuestion?.id; | ||
|
|
||
| if (isComplete || questionId >= currentQuestionId) { | ||
| return; | ||
| } | ||
| dispatchLocalState({ | ||
| type: QuestionTypes.JumpToQuestion, | ||
| payload: { questionId }, | ||
| }); | ||
| dispatchApiState({ | ||
| type: QuizAPIActionTypes.JUMP_TO_QUESTION, | ||
| payload: { questionId }, | ||
| }); | ||
| }, | ||
| [ | ||
| quizLocalState.isQuizCompleted, | ||
| quizApiState.quizCurrentQuestion?.id, | ||
| dispatchLocalState, | ||
| dispatchApiState, | ||
| ] | ||
| ); | ||
|
|
||
| return quizResetClickHandler; | ||
| }; | ||
|
|
||
| export default useJumpToQuestion; | ||
Uh oh!
There was an error while loading. Please reload this page.