Commented all related to shuffle
This commit is contained in:
@@ -17,26 +17,36 @@ function Question({
|
||||
}: MultipleChoiceQuestion & { userSolution: string | undefined; onSelectOption?: (option: string) => void; showSolution?: boolean }) {
|
||||
const { userSolutions } = useExamStore((state) => state);
|
||||
|
||||
/*
|
||||
const getShuffledOptions = (options: {id: string, text: string}[], questionShuffleMap: ShuffleMap) => {
|
||||
const shuffledOptions = ['A', 'B', 'C', 'D'].map(newId => {
|
||||
const originalId = questionShuffleMap.map[newId];
|
||||
const originalOption = options.find(option => option.id === originalId);
|
||||
return {
|
||||
id: newId,
|
||||
text: originalOption!.text
|
||||
};
|
||||
});
|
||||
return shuffledOptions;
|
||||
}
|
||||
|
||||
const getShuffledSolution = (originalSolution: string, questionShuffleMap: ShuffleMap) => {
|
||||
for (const [newPosition, originalPosition] of Object.entries(questionShuffleMap.map)) {
|
||||
if (originalPosition === originalSolution) {
|
||||
return newPosition;
|
||||
}
|
||||
}
|
||||
return originalSolution;
|
||||
}
|
||||
|
||||
const questionShuffleMap = userSolutions.reduce((foundMap, userSolution) => {
|
||||
if (foundMap) return foundMap;
|
||||
return userSolution.shuffleMaps?.find(map => map.id === id) || null;
|
||||
}, null as ShuffleMap | null);
|
||||
|
||||
const shuffledOptions = new Array(options.length);
|
||||
options.forEach(option => {
|
||||
const newId = questionShuffleMap?.map[option.id];
|
||||
const newIndex = options.findIndex(opt => opt.id === newId);
|
||||
shuffledOptions[newIndex] = option;
|
||||
});
|
||||
|
||||
const lettersMap = ['A', 'B', 'C', 'D'];
|
||||
const optionsWithLetters = shuffledOptions.map((option, index) => ({
|
||||
...option,
|
||||
id: lettersMap[index]
|
||||
}));
|
||||
|
||||
const questionOptions = questionShuffleMap ? optionsWithLetters : options;
|
||||
const newQuestionSolution = questionShuffleMap ? questionShuffleMap.map[solution] : solution;
|
||||
*/
|
||||
|
||||
const questionOptions = options; // questionShuffleMap ? getShuffledOptions(options as {id: string, text: string}[], questionShuffleMap) : options;
|
||||
const newSolution = solution; //questionShuffleMap ? getShuffledSolution(solution, questionShuffleMap) : solution;
|
||||
|
||||
const renderPrompt = (prompt: string) => {
|
||||
return reactStringReplace(prompt, /((<u>)[\w\s']+(<\/u>))/g, (match) => {
|
||||
@@ -46,11 +56,11 @@ function Question({
|
||||
};
|
||||
|
||||
const optionColor = (option: string) => {
|
||||
if (option === newQuestionSolution && !userSolution) {
|
||||
if (option === newSolution && !userSolution) {
|
||||
return "!border-mti-gray-davy !text-mti-gray-davy";
|
||||
}
|
||||
|
||||
if (option === newQuestionSolution) {
|
||||
if (option === newSolution) {
|
||||
return "!border-mti-purple-light !text-mti-purple-light";
|
||||
}
|
||||
|
||||
@@ -77,8 +87,8 @@ function Question({
|
||||
"flex flex-col items-center border border-mti-gray-platinum p-4 px-8 rounded-xl gap-4 cursor-pointer bg-white relative",
|
||||
optionColor(option!.id),
|
||||
)}>
|
||||
<span className={clsx("text-sm", newQuestionSolution !== option?.id && userSolution !== option?.id && "opacity-50")}>{option?.id}</span>
|
||||
<img src={option?.src!} alt={`Option ${option?.id}`} />
|
||||
<span className={clsx("text-sm", newSolution !== option?.id && userSolution !== option?.id && "opacity-50")}>{option?.id}</span>
|
||||
{"src" in option && <img src={option?.src!} alt={`Option ${option?.id}`} />}
|
||||
</div>
|
||||
))}
|
||||
{variant === "text" &&
|
||||
|
||||
Reference in New Issue
Block a user