diff --git a/frontend/src/pages/ReviewPage/ReviewPage.css b/frontend/src/pages/ReviewPage/ReviewPage.css index 3e430b6c..3ea75e9f 100644 --- a/frontend/src/pages/ReviewPage/ReviewPage.css +++ b/frontend/src/pages/ReviewPage/ReviewPage.css @@ -23,6 +23,14 @@ border-radius: 0.3rem; } +.red { + color: red !important; +} + +.green { + color:green !important; +} + .review-page-button { align-self: center; } \ No newline at end of file diff --git a/frontend/src/pages/ReviewPage/ReviewPage.tsx b/frontend/src/pages/ReviewPage/ReviewPage.tsx index 7f4bb947..5610f29a 100644 --- a/frontend/src/pages/ReviewPage/ReviewPage.tsx +++ b/frontend/src/pages/ReviewPage/ReviewPage.tsx @@ -28,6 +28,7 @@ export default function ReviewPage(props: Readonly) { const [userInput, setUserInput] = useState("") const [showFireworks, setShowFireworks] = useState(false); const [displayAnswer, setDisplayAnswer] = useState(false); + const [inputColor, setInputColor] = useState("inherit") const navigate = useNavigate() useEffect(() => { @@ -48,64 +49,74 @@ export default function ReviewPage(props: Readonly) { // }, []); useEffect(() => { - if (showFireworks) { - return - } - // TODO erst ¨¨berprüfen wenn vocastoreview geupdated sind - if (props.vocabsToReview.length < 1) { - navigate("/") - } else { - getNextVocab() - } - },[showFireworks]) - - function getNextVocab(): void { - setCurrentIndex(0) + if (showFireworks) { + return + } + // TODO erst überprüfen wenn vocabstoreview geupdated sind + if (props.vocabsToReview.length < 1) { + navigate("/") + } else { + getNextVocab() } + }, [showFireworks]) - function checkAnswer() { - const rightAnswers: string[] = getRightAnswers(currentVocab.word, - props.language) - const rightAnswersLowerCase = rightAnswers.map( - answer => answer.toLowerCase()) - const inputWithoutExtraSpaces: string = getInputWithoutExtraSpaces( - userInput) - if (rightAnswersLowerCase.includes(inputWithoutExtraSpaces)) { - setDisplayAnswer(true) - setShowFireworks(true) - setTimeout(() => { - setShowFireworks(false) - }, 2500); - setTimeout(() => { - setDisplayAnswer(false) - }, 2500); -setUserInput("") - } else { - props.changeReviewDates(currentVocab.id) - // TODO Zeige den Misserfolg irgendwie an - setDisplayAnswer(true) - } + function getNextVocab(): void { + setInputColor("inherit") + setCurrentIndex(0) + } - props.removeVocabFromVocabsToReview(currentVocab.id) + function checkAnswer() { + const rightAnswers: string[] = getRightAnswers(currentVocab.word, + props.language) + const rightAnswersLowerCase = rightAnswers.map( + answer => answer.toLowerCase()) + const inputWithoutExtraSpaces: string = getInputWithoutExtraSpaces( + userInput) + if (rightAnswersLowerCase.includes(inputWithoutExtraSpaces)) { + setDisplayAnswer(true) + setShowFireworks(true) + setInputColor("green") + setTimeout(() => { + setShowFireworks(false) + }, 2500); + setTimeout(() => { + setDisplayAnswer(false) + }, 2500); + setTimeout(() => { + setInputColor("inherit") + }, 2500); + // TODO wird das geleert? + setUserInput("") + } else { + props.changeReviewDates(currentVocab.id) + setInputColor("red") + setDisplayAnswer(true) } + props.removeVocabFromVocabsToReview(currentVocab.id) + } + - return (
- {showFireworks && } - {currentVocab && } - -
+ return (
+ {showFireworks && } + {currentVocab && } + +
setUserInput(element.target.value)} + className={inputColor} aria-label={"Enter your answer"} placeholder={"Type your answer here"} disabled={displayAnswer} /> - {!displayAnswer ? : } -
-
) - } \ No newline at end of file + {!displayAnswer ? + : } +
+
) +} \ No newline at end of file