diff --git a/src/components/Practice/Mechanics3.jsx b/src/components/Practice/Mechanics3.jsx index 76f1756e..7d9692cb 100644 --- a/src/components/Practice/Mechanics3.jsx +++ b/src/components/Practice/Mechanics3.jsx @@ -68,111 +68,9 @@ const Mechanics2 = ({ }); const lang = getLocalData("lang"); - let wordToCheck = type === "audio" ? parentWords : wordToFill; //console.log('Mechanics3', answer); - useEffect(() => { - const initializeFillInTheBlank = async () => { - if (type === "fillInTheBlank" && parentWords?.length) { - let wordsArr = parentWords.split(" "); - let randomIndex = Math.floor(Math.random() * wordsArr.length); - try { - await getSimilarWords(wordsArr[randomIndex]); - setWordToFill(wordsArr[randomIndex]); - // wordsArr[randomIndex] = "dash"; - setSentences(wordsArr); - setSelectedWord(""); - } catch (error) { - console.error("Error in initializeFillInTheBlank:", error); - } - } - }; - initializeFillInTheBlank(); - }, [contentId, parentWords]); - - useEffect(() => { - const initializeAudio = async () => { - if (type === "audio" && parentWords) { - setDisabledWords(true); - setSelectedWord(""); - try { - await getSimilarWords(parentWords); - } catch (error) { - console.error("Error in initializeAudio:", error); - } - } - }; - initializeAudio(); - }, [contentId, parentWords]); - - const getSimilarWords = async (wordForFindingHomophones) => { - const lang = getLocalData("lang"); - // const isFillInTheBlanks = type === "fillInTheBlank"; - const wordToSimilar = wordForFindingHomophones - ? wordForFindingHomophones - : parentWords; - - if (lang === "en") { - const finder = new HomophonesFinder(); - const homophones = await finder.find(wordToSimilar); - let wordsArr = [homophones[8], wordToSimilar, homophones[6]]; - setWords(randomizeArray(wordsArr)); - } else { - let wordsToShow = []; - if (type == "audio") { - wordsToShow = allWords?.filter((elem) => elem != wordToSimilar); - } - if (type == "fillInTheBlank") { - wordsToShow = allWords - ?.join(" ") - ?.split(" ") - .filter((elem) => elem !== wordToSimilar && elem.length > 2); - } - - wordsToShow = randomizeArray(wordsToShow).slice(0, 2); - wordsToShow.push(wordToSimilar); - setWords(randomizeArray(wordsToShow)); - } - }; - - const handleWord = (word, removeWord) => { - if (removeWord) { - setWords([...words, word]); - setSelectedWord(""); - setEnableNext(false); - } else { - let wordsArr = [...words]; - - if (type !== "audio") { - let index = wordsArr?.findIndex((elem) => elem === word); - if (index !== -1) { - wordsArr?.splice(index, 1); - } - } - - if (selectedWord && type !== "audio") { - wordsArr.push(selectedWord); - } - - // if (type === "audio") { - const isSoundCorrect = word === wordToCheck; - let audio = new Audio(isSoundCorrect ? correctSound : wrongSound); - if (!isSoundCorrect) { - setEnableNext(false); - } - audio.play(); - setShake(true); - setTimeout(() => { - setShake(false); - }, 800); - // } - - setWords(wordsArr); - setSelectedWord(word); - } - }; - useEffect(() => { if (!enableNext) { setAnswer({ text: "", audio_url: "", image_url: "", isAns: false }); @@ -224,20 +122,11 @@ const Mechanics2 = ({ ? 0 : currrentProgress / duration; - const getEnableButton = () => { - if (type === "fillInTheBlank") { - return enableNext; - } - if (type === "audio") { - return selectedWord === wordToCheck; - } - return false; - }; return ( @@ -374,7 +261,7 @@ const Mechanics2 = ({ style={{ borderRadius: "20px", maxWidth: "100%", - height: "250px", + height: "clamp(150px, 20vw, 220px)", }} alt="" /> @@ -385,7 +272,8 @@ const Mechanics2 = ({ sx={{ display: "flex", justifyContent: "center", - mt: { xs: "20px", sm: "40px" }, // Add margin-top to create space below the image + mt: { xs: "20px", sm: "40px" }, + width: "75%", }} > {answer?.text !== "" ? ( <> - {parentWords?.split("_____")[0]} {/* Before the blank */} + {parentWords?.split(/_+/)[0]} {answer?.text} - {parentWords?.split("_____")[1]} {/* After the blank */} + {parentWords?.split(/_+/)[1]} ) : ( <>{parentWords} @@ -438,52 +326,9 @@ const Mechanics2 = ({ justifyContent: "center", marginTop: "20px", marginBottom: "30px", + flexWrap: "wrap", }} > - {type === "audio" && - words?.map((elem, ind) => ( - handleWord(elem)} - sx={{ - textAlign: "center", - px: "25px", - py: "12px", - // background: "transparent", - m: 1, - textTransform: "none", - borderRadius: "12px", - border: `1px solid rgba(51, 63, 97, 0.10)`, - background: "#FFF", - cursor: "pointer", - opacity: disabledWords ? 0.25 : 1, - pointerEvents: disabledWords ? "none" : "initial", - }} - > - - {elem} - - - ))} <> {type === "fillInTheBlank" && Array.isArray(options) && @@ -550,7 +395,7 @@ const Mechanics2 = ({ dontShowListen={type === "image" || isDiscover} // updateStory={updateStory} originalText={parentWords} - enableNext={getEnableButton()} + enableNext={enableNext} handleNext={handleNext} audioLink={audio ? audio : null} {...{ diff --git a/src/views/Practice/Practice.jsx b/src/views/Practice/Practice.jsx index 7b436aa0..5fd15360 100644 --- a/src/views/Practice/Practice.jsx +++ b/src/views/Practice/Practice.jsx @@ -716,9 +716,11 @@ const Practice = () => { questions[currentQuestion]?.contentSourceData || []; const stringLengths = contentSourceData.map((item) => item.text.length); const length = - questions[currentQuestion]?.mechanics_data && + (questions[currentQuestion]?.mechanics_data && + questions[currentQuestion]?.mechanics_data[0]?.mechanics_id === + "mechanic_2") || questions[currentQuestion]?.mechanics_data[0]?.mechanics_id === - "mechanic_2" + "mechanic_1" ? 500 : stringLengths[0]; window.parent.postMessage({ type: "stringLengths", length }, "*");