diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 3bae6fbf..1d989844 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -34,6 +34,9 @@ function App() { const [displayNewVocabsPopUp, setDisplayNewVocabsPopUp] = useState(false) const navigate = useNavigate() + console.log("vocabsToReview: ", vocabsToReview) + + useEffect(() => { getUserId() }, []); @@ -55,7 +58,7 @@ function App() { } else { navigate("/login") } - }, [userId]); + }, [userId]); function getAllVocabsOfLanguage() { if (!language || !userId) { @@ -84,21 +87,33 @@ function App() { } function updateVocabsToReview(): void { - if (!userId || !language || !vocabs) { - return - } + const oldTodaysVocabs: Vocab[] = todaysVocabs const updatedTodaysVocabs: Vocab[] = getTodaysVocabs() - const vocabsToReviewWithoutDeletedOnes: Vocab[] = vocabsToReview - .filter((vocabToReview: Vocab) => updatedTodaysVocabs - .find( - vocabFromTodays => vocabFromTodays.id === vocabToReview.id)) + // nicht in toReview, nicht in alten todays, nur in neuen todays -> + // muss in neue toReview const newVocabs: Vocab[] = updatedTodaysVocabs - .filter(vocabFromUpdatedOnes => todaysVocabs - .find((vocabFromOldOnes: Vocab) => vocabFromOldOnes.id != - vocabFromUpdatedOnes.id)) - const updatedVocabsToReview: Vocab[] = [...vocabsToReviewWithoutDeletedOnes, - ...newVocabs] - setVocabsToReview(updatedVocabsToReview) + .filter(vocabOfOldOnes => !oldTodaysVocabs + .some(vocabOfUpdatedOnes => vocabOfUpdatedOnes.id === + vocabOfOldOnes.id)) + console.log("newVocabs :", newVocabs) + // egal ob in alten toReview, in alten todays, nicht in neuen todays + // -> darf nicht in neue toReview + const deactivatedVocabs: Vocab[] = oldTodaysVocabs + .filter(vocabOfOldOnes => !updatedTodaysVocabs + .some(vocabOfUpdatedOnes => vocabOfUpdatedOnes.id === + vocabOfOldOnes.id)) + // nimm die deaktivierten aus den toReview raus + let vocabsToReviewWithoutDeactivatedOnes: Vocab[] = [] + if (vocabsToReview.length > 0) { + vocabsToReviewWithoutDeactivatedOnes = + vocabsToReview.filter(vocabToReview => !deactivatedVocabs + .some(deactivatedVocab => deactivatedVocab.id === + vocabToReview.id)) + } + console.log("vocabsToReviewWithoutDeactivatedOnes: ", + vocabsToReviewWithoutDeactivatedOnes) + setVocabsToReview( + [...vocabsToReviewWithoutDeactivatedOnes, ...newVocabs]) setTodaysVocabs(updatedTodaysVocabs) } @@ -154,8 +169,7 @@ function App() { function changeReviewDates(id: string | null): void { axios.put(`api/vocab/change-dates/${id}`) .then(() => { - console.log( - `Vocab ${id}'s review dates successfully updated.`) + console.log(`Vocab ${id}'s review dates successfully updated.`) getAllVocabsOfLanguage() }) .catch(error => { @@ -279,9 +293,12 @@ function App() { changeReviewDates={changeReviewDates}/>}/> vocab.datesPerUser && - Object.keys(vocab.datesPerUser).length !== 0 || - !vocab.datesPerUser?.userId)} + vocabs={vocabs.filter( + vocab => { + if (!vocab.datesPerUser) {return true} + if (!vocab.datesPerUser[userId]) {return true} + if (vocab.datesPerUser[userId].length < 1) {return true} + })} deleteVocab={deleteVocab} activateVocab={activateVocab} language={language} diff --git a/frontend/src/pages/ReviewPage/ReviewPage.tsx b/frontend/src/pages/ReviewPage/ReviewPage.tsx index 6eb38b95..22fddd57 100644 --- a/frontend/src/pages/ReviewPage/ReviewPage.tsx +++ b/frontend/src/pages/ReviewPage/ReviewPage.tsx @@ -76,14 +76,22 @@ export default function ReviewPage(props: Readonly) { // navigate("/") // }, 5000); // } + props.removeVocabFromVocabsToReview(currentVocab.id) } else { props.changeReviewDates(currentVocab.id) + // TODO Färbung funktioniert nicht setInputColor("red") setDisplayAnswer(true) - toast.error( - "Wrong answer. Changing review dates for this vocab.") + // TODO passendere lösung als das errormessage für die rückmeldung (nicht sinnvoll) + // TODO custom toast message? ohne rote färbung? + // toast.error( + // "Wrong answer. Changing review dates for this vocab.") + setTimeout(() => { + props.changeReviewDates(currentVocab.id); + props.removeVocabFromVocabsToReview(currentVocab.id); + }, 1000); } - props.removeVocabFromVocabsToReview(currentVocab.id) + } return (