Arreglar que suenen varios audios al mismo tiempo
This commit is contained in:
parent
bf17617099
commit
61bd6fca46
1 changed files with 112 additions and 0 deletions
112
patches/0008-use-audio-hook-in-selection-questions.diff
Normal file
112
patches/0008-use-audio-hook-in-selection-questions.diff
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
diff -Naur orig/components/Lesson/LessonExercise/MultiSelectionExercise/MultiSelectionQuestionRow.jsx parcheado/components/Lesson/LessonExercise/MultiSelectionExercise/MultiSelectionQuestionRow.jsx
|
||||||
|
--- orig/components/Lesson/LessonExercise/MultiSelectionExercise/MultiSelectionQuestionRow.jsx 2021-10-13 10:10:23.486696645 -0300
|
||||||
|
+++ parcheado/components/Lesson/LessonExercise/MultiSelectionExercise/MultiSelectionQuestionRow.jsx 2021-10-15 13:48:08.065899802 -0300
|
||||||
|
@@ -49,7 +49,10 @@
|
||||||
|
achievableScore,
|
||||||
|
});
|
||||||
|
|
||||||
|
- const { playWrongDefaultAudioFeedBack, playCorrectDefaultAudioFeedBack } = useAudio();
|
||||||
|
+ const {
|
||||||
|
+ playAudio, addRef: addAudioRef,
|
||||||
|
+ playWrongDefaultAudioFeedBack, playCorrectDefaultAudioFeedBack,
|
||||||
|
+ } = useAudio();
|
||||||
|
const correctAnswerAudioRef = useRef();
|
||||||
|
const answersRef = useRef(answers);
|
||||||
|
const isMountedRef = useIsMountedRef();
|
||||||
|
@@ -57,7 +60,8 @@
|
||||||
|
useEffect(() => {
|
||||||
|
// eslint-disable-next-line fp/no-mutation
|
||||||
|
answersRef.current = answers;
|
||||||
|
- });
|
||||||
|
+ addAudioRef(correctAnswerAudioRef);
|
||||||
|
+ }, [addAudioRef]);
|
||||||
|
|
||||||
|
const selectOrUnselectAnswer = chosenAnswerIndex => {
|
||||||
|
const updatedAnswers = answers.map((answer, index) => {
|
||||||
|
@@ -98,9 +102,9 @@
|
||||||
|
return updatedAnswers;
|
||||||
|
};
|
||||||
|
|
||||||
|
- const playSuccessAudio = () => {
|
||||||
|
+ const playSuccessAudio = e => {
|
||||||
|
if (correctAnswerAudioUrl) {
|
||||||
|
- correctAnswerAudioRef.current.play();
|
||||||
|
+ playAudio(e, correctAnswerAudioRef);
|
||||||
|
} else {
|
||||||
|
playCorrectDefaultAudioFeedBack();
|
||||||
|
}
|
||||||
|
@@ -120,16 +124,16 @@
|
||||||
|
selectOrUnselectAnswer(chosenAnswerIndex);
|
||||||
|
};
|
||||||
|
|
||||||
|
- const onHandleSolveButtonClicked = () => {
|
||||||
|
+ const onHandleSolveButtonClicked = e => {
|
||||||
|
handleSolved();
|
||||||
|
- playSuccessAudio();
|
||||||
|
+ playSuccessAudio(e);
|
||||||
|
updateAnswers(answers, answer =>
|
||||||
|
answer.isCorrect ? ANSWER_STATE.SOLVED : ANSWER_STATE.INITIAL,
|
||||||
|
);
|
||||||
|
setAnswersFrozen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
- const onHandleCheckButtonClicked = () => {
|
||||||
|
+ const onHandleCheckButtonClicked = e => {
|
||||||
|
const checkedAnswers = updateAnswers(
|
||||||
|
answers,
|
||||||
|
answer => (answer.isCorrect ? ANSWER_STATE.CORRECT : ANSWER_STATE.WRONG),
|
||||||
|
@@ -138,7 +142,7 @@
|
||||||
|
|
||||||
|
if (isSolvedCorrectly(checkedAnswers)) {
|
||||||
|
handleCorrectAnswer();
|
||||||
|
- playSuccessAudio();
|
||||||
|
+ playSuccessAudio(e);
|
||||||
|
setAnswersFrozen(true);
|
||||||
|
} else {
|
||||||
|
handleWrongAnswer();
|
||||||
|
diff -Naur orig/components/Lesson/LessonExercise/SingleSelectionExercise/SingleSelectionQuestionRow/SingleSelectionQuestionRow.jsx parcheado/components/Lesson/LessonExercise/SingleSelectionExercise/SingleSelectionQuestionRow/SingleSelectionQuestionRow.jsx
|
||||||
|
--- orig/components/Lesson/LessonExercise/SingleSelectionExercise/SingleSelectionQuestionRow/SingleSelectionQuestionRow.jsx 2021-10-13 10:10:23.446697050 -0300
|
||||||
|
+++ parcheado/components/Lesson/LessonExercise/SingleSelectionExercise/SingleSelectionQuestionRow/SingleSelectionQuestionRow.jsx 2021-10-15 13:44:06.353710138 -0300
|
||||||
|
@@ -35,7 +35,10 @@
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
- const { playWrongDefaultAudioFeedBack, playCorrectDefaultAudioFeedBack } = useAudio();
|
||||||
|
+ const {
|
||||||
|
+ playAudio, addRef: addAudioRef,
|
||||||
|
+ playWrongDefaultAudioFeedBack, playCorrectDefaultAudioFeedBack,
|
||||||
|
+ } = useAudio();
|
||||||
|
const correctAnswerAudioRef = useRef();
|
||||||
|
const answersRef = useRef(answers);
|
||||||
|
const { handleCorrectAnswer, handleWrongAnswer, isFromPlacementCourse } = useInquiryHandling({
|
||||||
|
@@ -47,7 +50,8 @@
|
||||||
|
useEffect(() => {
|
||||||
|
// eslint-disable-next-line fp/no-mutation
|
||||||
|
answersRef.current = answers;
|
||||||
|
- });
|
||||||
|
+ addAudioRef(correctAnswerAudioRef);
|
||||||
|
+ }, [addAudioRef]);
|
||||||
|
|
||||||
|
const getAnswerState = ({ index, chosenAnswerIndex, selectCurrentAnswer, answer }) => {
|
||||||
|
const { answerState, isCorrect } = answer;
|
||||||
|
@@ -80,6 +84,11 @@
|
||||||
|
e.preventDefault();
|
||||||
|
answersRefArray[chosenAnswerIndex].blur();
|
||||||
|
if (answersFrozen) {
|
||||||
|
+ if (correctAnswerAudioUrl) {
|
||||||
|
+ playAudio(e, correctAnswerAudioRef);
|
||||||
|
+ } else {
|
||||||
|
+ playCorrectDefaultAudioFeedBack();
|
||||||
|
+ }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateAnswers(chosenAnswerIndex, true);
|
||||||
|
@@ -88,7 +97,7 @@
|
||||||
|
handleCorrectAnswer();
|
||||||
|
setAnswersFrozen(true);
|
||||||
|
if (correctAnswerAudioUrl) {
|
||||||
|
- correctAnswerAudioRef.current.play();
|
||||||
|
+ playAudio(e, correctAnswerAudioRef);
|
||||||
|
} else {
|
||||||
|
playCorrectDefaultAudioFeedBack();
|
||||||
|
}
|
Loading…
Reference in a new issue