Enable sound effects
This commit is contained in:
BIN
src/CorrectSound.mp3
Normal file
BIN
src/CorrectSound.mp3
Normal file
Binary file not shown.
BIN
src/IncorrectSound.mp3
Normal file
BIN
src/IncorrectSound.mp3
Normal file
Binary file not shown.
@@ -9,6 +9,8 @@ import Footer from "./Footer";
|
|||||||
import LineChart from './LineChart';
|
import LineChart from './LineChart';
|
||||||
import ProgressStats from './ProgressStats';
|
import ProgressStats from './ProgressStats';
|
||||||
import ConfirmationDialog from "./ConfirmationDialog";
|
import ConfirmationDialog from "./ConfirmationDialog";
|
||||||
|
import CorrectSound from "./CorrectSound.mp3";
|
||||||
|
import IncorrectSound from "./IncorrectSound.mp3";
|
||||||
|
|
||||||
import "./css/PopUp.css";
|
import "./css/PopUp.css";
|
||||||
import "./css/Progress.css";
|
import "./css/Progress.css";
|
||||||
@@ -55,6 +57,7 @@ export default withRouter(class Progress extends React.Component {
|
|||||||
averagePercentage: null,
|
averagePercentage: null,
|
||||||
pageLoaded: false,
|
pageLoaded: false,
|
||||||
startTime: null,
|
startTime: null,
|
||||||
|
sound: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -89,6 +92,9 @@ export default withRouter(class Progress extends React.Component {
|
|||||||
get: () => isMounted,
|
get: () => isMounted,
|
||||||
set: (value) => isMounted = value,
|
set: (value) => isMounted = value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.correctSound = new Audio(CorrectSound);
|
||||||
|
this.incorrectSound = new Audio(IncorrectSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState = (state, callback=null) => {
|
setState = (state, callback=null) => {
|
||||||
@@ -350,23 +356,22 @@ export default withRouter(class Progress extends React.Component {
|
|||||||
canStartTest: true,
|
canStartTest: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.correct) {
|
|
||||||
this.props.logEvent("correct_answer", {
|
|
||||||
progress_id: this.props.match.params.progressId,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.props.logEvent("incorrect_answer", {
|
|
||||||
progress_id: this.props.match.params.progressId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.state.mode === "lives") newState.lives = data.lives;
|
if (this.state.mode === "lives") newState.lives = data.lives;
|
||||||
|
|
||||||
if (data.correct) {
|
if (data.correct) {
|
||||||
// correct answer given
|
// correct answer given
|
||||||
newState.answerInput = "";
|
newState.answerInput = "";
|
||||||
|
// play sound
|
||||||
|
if (this.props.sound) {
|
||||||
|
this.correctSound.currentTime = 0;
|
||||||
|
this.correctSound.play();
|
||||||
|
}
|
||||||
// show next question if there are no more answers
|
// show next question if there are no more answers
|
||||||
if (!data.moreAnswers) newState = this.showNextQuestion(newState, newState);
|
if (!data.moreAnswers) newState = this.showNextQuestion(newState, newState);
|
||||||
|
|
||||||
|
this.props.logEvent("correct_answer", {
|
||||||
|
progress_id: this.props.match.params.progressId,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// incorrect answer given
|
// incorrect answer given
|
||||||
// store prompt and count=0
|
// store prompt and count=0
|
||||||
@@ -377,6 +382,15 @@ export default withRouter(class Progress extends React.Component {
|
|||||||
answer: data.lives === 0 ? data.correctAnswers : "",
|
answer: data.lives === 0 ? data.correctAnswers : "",
|
||||||
count: 0,
|
count: 0,
|
||||||
};
|
};
|
||||||
|
// play sound
|
||||||
|
if (this.props.sound) {
|
||||||
|
this.incorrectSound.currentTime = 0;
|
||||||
|
this.incorrectSound.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.logEvent("incorrect_answer", {
|
||||||
|
progress_id: this.props.match.params.progressId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((data.correct || data.lives === 0) && !data.moreAnswers && this.state.incorrectAnswers[data.currentVocabId]) {
|
if ((data.correct || data.lives === 0) && !data.moreAnswers && this.state.incorrectAnswers[data.currentVocabId]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user