Skip to content

Commit

Permalink
fix filtering of inactive vocabs to be passed from app to backlog page
Browse files Browse the repository at this point in the history
  • Loading branch information
nora-kauczor committed Nov 9, 2024
1 parent 834703b commit 99090fd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
55 changes: 36 additions & 19 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function App() {
const [displayNewVocabsPopUp, setDisplayNewVocabsPopUp] = useState(false)
const navigate = useNavigate()

console.log("vocabsToReview: ", vocabsToReview)


useEffect(() => {
getUserId()
}, []);
Expand All @@ -55,7 +58,7 @@ function App() {
} else {
navigate("/login")
}
}, [userId]);
}, [userId]);

function getAllVocabsOfLanguage() {
if (!language || !userId) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -279,9 +293,12 @@ function App() {
changeReviewDates={changeReviewDates}/>}/>
<Route path={"/backlog"}
element={<BacklogPage
vocabs={vocabs.filter(vocab => 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}
Expand Down
14 changes: 11 additions & 3 deletions frontend/src/pages/ReviewPage/ReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ export default function ReviewPage(props: Readonly<Props>) {
// 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 (<div id={"review-page"} className={"page"} role={"main"}>
Expand Down

0 comments on commit 99090fd

Please sign in to comment.