fixing matching pairs send data
This commit is contained in:
parent
3b447efeae
commit
6f5645d158
|
|
@ -54,7 +54,6 @@ export const useExercises = (topic, level) => {
|
|||
ANSWER_STUDENT: answer
|
||||
};
|
||||
setAnswers(newAnswers);
|
||||
// localStorage.setItem(levelId, JSON.stringify(newAnswers));
|
||||
localStorage.setItem(learningId, JSON.stringify(newAnswers));
|
||||
};
|
||||
|
||||
|
|
@ -98,7 +97,7 @@ export const useExercises = (topic, level) => {
|
|||
} catch (error) {
|
||||
console.error(error);
|
||||
}finally{
|
||||
// navigate(`/learning/module/${section}/${topic}/${level}/result`);
|
||||
navigate(`/learning/module/${section}/${topic}/${level}/result`);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,17 @@ function stringToArray(str) {
|
|||
return str.split(', ');
|
||||
}
|
||||
|
||||
function extractAnswer(input) {
|
||||
const lines = input.split('|');
|
||||
|
||||
const descriptions = lines.map(line => {
|
||||
const parts = line.split('>');
|
||||
return parts[1]?.trim();
|
||||
});
|
||||
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
const MatchingPairsQuestion = ({ question, onAnswer, studentAnswer, index }) => {
|
||||
const savedAnswer = studentAnswer !== null ? studentAnswer.ANSWER_STUDENT : null;
|
||||
const [pairs, setPairs] = useState([]);
|
||||
|
|
@ -54,7 +65,12 @@ const MatchingPairsQuestion = ({ question, onAnswer, studentAnswer, index }) =>
|
|||
}));
|
||||
|
||||
if (savedAnswer !== null) {
|
||||
const arrSavedAnswer = stringToArray(savedAnswer);
|
||||
//if use "," as separator
|
||||
// const arrSavedAnswer = stringToArray(savedAnswer);
|
||||
|
||||
//if use ">" as separator
|
||||
const arrSavedAnswer = extractAnswer(savedAnswer);
|
||||
|
||||
const updatedPairs = initialPairs.map((pair, index) => ({
|
||||
...pair,
|
||||
right: arrSavedAnswer[index],
|
||||
|
|
@ -105,13 +121,14 @@ const MatchingPairsQuestion = ({ question, onAnswer, studentAnswer, index }) =>
|
|||
setIsComplete(true);
|
||||
|
||||
const rightAnswers = newPairs.map((pair) => pair.right);
|
||||
// onAnswer(index, arrayToString(rightAnswers), question.ID_ADMIN_EXERCISE);
|
||||
|
||||
const stringPairs = newPairs
|
||||
.map(pair => `${pair.left}>${pair.right}`)
|
||||
.join("| ");
|
||||
|
||||
// onAnswer(index, arrayToString(rightAnswers), question.ID_ADMIN_EXERCISE);
|
||||
onAnswer(index, stringPairs, question.ID_ADMIN_EXERCISE);
|
||||
// console.log(stringPairs);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user