mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-09 16:53:33 +02:00
wip
This commit is contained in:
@@ -5,6 +5,7 @@ import { AIOpenEndedQuestion } from './AIOpenEndedQuestion';
|
|||||||
import { QuizTopNavigation } from './QuizTopNavigation';
|
import { QuizTopNavigation } from './QuizTopNavigation';
|
||||||
import { getPercentage } from '../../lib/number';
|
import { getPercentage } from '../../lib/number';
|
||||||
import { AIQuizResults } from './AIQuizResults';
|
import { AIQuizResults } from './AIQuizResults';
|
||||||
|
import { flushSync } from 'react-dom';
|
||||||
|
|
||||||
export type QuestionState = {
|
export type QuestionState = {
|
||||||
isSubmitted: boolean;
|
isSubmitted: boolean;
|
||||||
@@ -45,10 +46,12 @@ export function AIQuizContent(props: AIQuizContentProps) {
|
|||||||
|
|
||||||
const handleSubmit = (status: QuestionState['status']) => {
|
const handleSubmit = (status: QuestionState['status']) => {
|
||||||
setQuestionStates((prev) => {
|
setQuestionStates((prev) => {
|
||||||
|
const oldState = prev[activeQuestionIndex] ?? DEFAULT_QUESTION_STATE;
|
||||||
|
|
||||||
const newSelectedOptions = {
|
const newSelectedOptions = {
|
||||||
...prev,
|
...prev,
|
||||||
[activeQuestionIndex]: {
|
[activeQuestionIndex]: {
|
||||||
...activeQuestionState,
|
...oldState,
|
||||||
isSubmitted: true,
|
isSubmitted: true,
|
||||||
status,
|
status,
|
||||||
},
|
},
|
||||||
@@ -62,10 +65,12 @@ export function AIQuizContent(props: AIQuizContentProps) {
|
|||||||
|
|
||||||
const handleSetUserAnswer = (userAnswer: string) => {
|
const handleSetUserAnswer = (userAnswer: string) => {
|
||||||
setQuestionStates((prev) => {
|
setQuestionStates((prev) => {
|
||||||
|
const oldState = prev[activeQuestionIndex] ?? DEFAULT_QUESTION_STATE;
|
||||||
|
|
||||||
const newSelectedOptions = {
|
const newSelectedOptions = {
|
||||||
...prev,
|
...prev,
|
||||||
[activeQuestionIndex]: {
|
[activeQuestionIndex]: {
|
||||||
...activeQuestionState,
|
...oldState,
|
||||||
userAnswer,
|
userAnswer,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -75,25 +80,31 @@ export function AIQuizContent(props: AIQuizContentProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSetCorrectAnswer = (correctAnswer: string) => {
|
const handleSetCorrectAnswer = (correctAnswer: string) => {
|
||||||
setQuestionStates((prev) => {
|
flushSync(() => {
|
||||||
const newSelectedOptions = {
|
setQuestionStates((prev) => {
|
||||||
...prev,
|
const oldState = prev[activeQuestionIndex] ?? DEFAULT_QUESTION_STATE;
|
||||||
[activeQuestionIndex]: {
|
|
||||||
...activeQuestionState,
|
|
||||||
correctAnswer,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return newSelectedOptions;
|
const newSelectedOptions = {
|
||||||
|
...prev,
|
||||||
|
[activeQuestionIndex]: {
|
||||||
|
...oldState,
|
||||||
|
correctAnswer,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return newSelectedOptions;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectOptions = (options: number[]) => {
|
const handleSelectOptions = (options: number[]) => {
|
||||||
setQuestionStates((prev) => {
|
setQuestionStates((prev) => {
|
||||||
|
const oldState = prev[activeQuestionIndex] ?? DEFAULT_QUESTION_STATE;
|
||||||
|
|
||||||
const newSelectedOptions = {
|
const newSelectedOptions = {
|
||||||
...prev,
|
...prev,
|
||||||
[activeQuestionIndex]: {
|
[activeQuestionIndex]: {
|
||||||
...activeQuestionState,
|
...oldState,
|
||||||
selectedOptions: options,
|
selectedOptions: options,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user