updateCard(flashcard: Flashcard) {
setState("flashcards", "collections", (collections: FlashcardCollection[]) => {
const tempCollections = [...collections]
return tempCollections.map((collection) => {
const tempCollection = {...collection}
const cards = [...tempCollection.flashcards]
tempCollection.flashcards = cards.map((currentCard) => {
if (currentCard.id !== flashcard.id) {
return currentCard
}
return Object.assign({}, currentCard, flashcard)
})
return tempCollection
})
})
}
updateCard(flashcard: Flashcard) {
setState("flashcards", "collections", (collections: FlashcardCollection[]) => {
const tempCollections = [...collections]
return tempCollections.map((collection) => {
const tempCollection = {...collection}
const cards = [...tempCollection.flashcards]
tempCollection.flashcards = cards.map((currentCard) => {
if (currentCard.id !== flashcard.id) {
return currentCard
}
return Object.assign({}, currentCard, flashcard)
})
return tempCollection
})
})
}