import {FillBlanksExercise} from "@/interfaces/exam"; import clsx from "clsx"; import reactStringReplace from "react-string-replace"; import {CommonProps} from "."; import {Fragment} from "react"; import Button from "../Low/Button"; export default function FillBlanksSolutions({id, type, prompt, solutions, text, userSolutions, onNext, onBack}: FillBlanksExercise & CommonProps) { const calculateScore = () => { const total = text.match(/({{\d+}})/g)?.length || 0; const correct = userSolutions.filter((x) => solutions.find((y) => x.id === y.id)?.solution === x.solution.toLowerCase() || false).length; const missing = total - userSolutions.filter((x) => solutions.find((y) => x.id === y.id)).length; return {total, correct, missing}; }; const renderLines = (line: string) => { return ( {reactStringReplace(line, /({{\d}})/g, (match) => { const id = match.replaceAll(/[\{\}]/g, ""); const userSolution = userSolutions.find((x) => x.id === id); const solution = solutions.find((x) => x.id === id)!; if (!userSolution) { return ( ); } if (userSolution.solution === solution.solution) { return ( ); } if (userSolution.solution !== solution.solution) { return ( <> > ); } })} ); }; return ( <>
{renderLines(line)}