This commit is contained in:
lingdocs 2022-04-12 16:48:10 +05:00
parent 2621a0e615
commit 55f4eaa1bb
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/pashto-inflector",
"version": "1.9.3",
"version": "1.9.4",
"author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com",

View File

@ -18,6 +18,7 @@ import InlinePs from "../InlinePs";
import { psStringEquals } from "../../lib/p-text-helpers";
import classNames from "classnames";
import { randFromArray } from "../../lib/misc-helpers";
import playAudio from "../../lib/play-audio";
// import { useReward } from 'react-rewards';
const kingEmoji = "👑";
@ -144,6 +145,8 @@ export function VPExplorer(props: {
function checkQuizAnswer(a: T.PsString) {
if (!quizState) return;
if (isInAnswer(a, quizState.answer)) {
const toPlay = randFromArray([true, false, false]);
if (toPlay) playAudio(`correct-${randFromArray([1,2,3])}`);
setShowCheck(true);
setTimeout(() => {
handleResetQuiz();
@ -156,6 +159,7 @@ export function VPExplorer(props: {
setCurrentCorrectEmoji(randFromArray(correctEmoji));
}, checkDuration * 2);
} else {
playAudio(`wrong-${randFromArray([1,2])}`);
navigator.vibrate(250);
setQuizState({
...quizState,

11
src/lib/play-audio.ts Normal file
View File

@ -0,0 +1,11 @@
export default function playAudio(a: string) {
if (!a) return;
let audio = new Audio(`https://verbs.lingdocs.com/sounds/${a}.mp3`);
audio.addEventListener("ended", () => {
audio.remove();
audio.srcObject = null;
});
audio.play().catch((e) => {
console.error(e);
});
}