This commit is contained in:
Liang Ding 2023-03-22 14:44:34 +08:00
parent f569df8efd
commit e6218a61b5
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
3 changed files with 42 additions and 20 deletions

View File

@ -196,7 +196,7 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
deckID: blocks[index].deckID, deckID: blocks[index].deckID,
cardID: blocks[index].cardID, cardID: blocks[index].cardID,
rating: parseInt(type), rating: parseInt(type),
reviewedCardIDs: blocks reviewedCards: blocks
}, () => { }, () => {
/// #if MOBILE /// #if MOBILE
if (type !== "-3" && if (type !== "-3" &&
@ -213,7 +213,7 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
rootID: titleElement.getAttribute("data-id"), rootID: titleElement.getAttribute("data-id"),
deckID: selectElement?.value, deckID: selectElement?.value,
notebook: titleElement.getAttribute("data-notebookid"), notebook: titleElement.getAttribute("data-notebookid"),
reviewedCardIDs: blocks reviewedCards: blocks
}, (treeCards) => { }, (treeCards) => {
index = 0; index = 0;
blocks = treeCards.data; blocks = treeCards.data;

View File

@ -96,7 +96,8 @@ func reviewRiffCard(c *gin.Context) {
deckID := arg["deckID"].(string) deckID := arg["deckID"].(string)
cardID := arg["cardID"].(string) cardID := arg["cardID"].(string)
rating := int(arg["rating"].(float64)) rating := int(arg["rating"].(float64))
err := model.ReviewFlashcard(deckID, cardID, riff.Rating(rating)) reviewedCardIDs := getReviewedCards(arg)
err := model.ReviewFlashcard(deckID, cardID, riff.Rating(rating), reviewedCardIDs)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -133,7 +134,8 @@ func getNotebookRiffDueCards(c *gin.Context) {
} }
notebookID := arg["notebook"].(string) notebookID := arg["notebook"].(string)
cards, err := model.GetNotebookDueFlashcards(notebookID) reviewedCardIDs := getReviewedCards(arg)
cards, err := model.GetNotebookDueFlashcards(notebookID, reviewedCardIDs)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -153,7 +155,8 @@ func getTreeRiffDueCards(c *gin.Context) {
} }
rootID := arg["rootID"].(string) rootID := arg["rootID"].(string)
cards, err := model.GetTreeDueFlashcards(rootID) reviewedCardIDs := getReviewedCards(arg)
cards, err := model.GetTreeDueFlashcards(rootID, reviewedCardIDs)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -173,7 +176,8 @@ func getRiffDueCards(c *gin.Context) {
} }
deckID := arg["deckID"].(string) deckID := arg["deckID"].(string)
cards, err := model.GetDueFlashcards(deckID) reviewedCardIDs := getReviewedCards(arg)
cards, err := model.GetDueFlashcards(deckID, reviewedCardIDs)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -183,6 +187,20 @@ func getRiffDueCards(c *gin.Context) {
ret.Data = cards ret.Data = cards
} }
func getReviewedCards(arg map[string]interface{}) (ret []string) {
if nil == arg["reviewedCards"] {
return
}
reviewedCardsArg := arg["reviewedCards"].([]interface{})
for _, card := range reviewedCardsArg {
c := card.(map[string]interface{})
cardID := c["cardID"].(string)
ret = append(ret, cardID)
}
return
}
func removeRiffCards(c *gin.Context) { func removeRiffCards(c *gin.Context) {
ret := gulu.Ret.NewResult() ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret) defer c.JSON(http.StatusOK, ret)

View File

@ -190,7 +190,7 @@ var (
skipCardCache = map[string]riff.Card{} skipCardCache = map[string]riff.Card{}
) )
func ReviewFlashcard(deckID, cardID string, rating riff.Rating) (err error) { func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs []string) (err error) {
deckLock.Lock() deckLock.Lock()
defer deckLock.Unlock() defer deckLock.Unlock()
@ -224,7 +224,7 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating) (err error) {
return return
} }
dueCards := getDueFlashcards(deckID) dueCards := getDueFlashcards(deckID, reviewedCardIDs)
if 1 > len(dueCards) { if 1 > len(dueCards) {
// 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存 // 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存
reviewCardCache = map[string]riff.Card{} reviewCardCache = map[string]riff.Card{}
@ -273,7 +273,7 @@ func newFlashcard(card riff.Card, blockID, deckID string, now time.Time) *Flashc
} }
} }
func GetNotebookDueFlashcards(boxID string) (ret []*Flashcard, err error) { func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
deckLock.Lock() deckLock.Lock()
defer deckLock.Unlock() defer deckLock.Unlock()
@ -315,7 +315,7 @@ func GetNotebookDueFlashcards(boxID string) (ret []*Flashcard, err error) {
return return
} }
cards := getDeckDueCards(deck) cards := getDeckDueCards(deck, reviewedCardIDs)
now := time.Now() now := time.Now()
for _, card := range cards { for _, card := range cards {
blockID := card.BlockID() blockID := card.BlockID()
@ -331,7 +331,7 @@ func GetNotebookDueFlashcards(boxID string) (ret []*Flashcard, err error) {
return return
} }
func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) { func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
deckLock.Lock() deckLock.Lock()
defer deckLock.Unlock() defer deckLock.Unlock()
@ -346,7 +346,7 @@ func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {
} }
treeBlockIDs := getTreeSubTreeChildBlocks(rootID) treeBlockIDs := getTreeSubTreeChildBlocks(rootID)
cards := getDeckDueCards(deck) cards := getDeckDueCards(deck, reviewedCardIDs)
now := time.Now() now := time.Now()
for _, card := range cards { for _, card := range cards {
blockID := card.BlockID() blockID := card.BlockID()
@ -400,7 +400,7 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs map[string]bool) {
return return
} }
func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
deckLock.Lock() deckLock.Lock()
defer deckLock.Unlock() defer deckLock.Unlock()
@ -410,22 +410,22 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
} }
if "" == deckID { if "" == deckID {
ret = getAllDueFlashcards() ret = getAllDueFlashcards(reviewedCardIDs)
return return
} }
ret = getDueFlashcards(deckID) ret = getDueFlashcards(deckID, reviewedCardIDs)
return return
} }
func getDueFlashcards(deckID string) (ret []*Flashcard) { func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard) {
deck := Decks[deckID] deck := Decks[deckID]
if nil == deck { if nil == deck {
logging.LogWarnf("deck not found [%s]", deckID) logging.LogWarnf("deck not found [%s]", deckID)
return return
} }
cards := getDeckDueCards(deck) cards := getDeckDueCards(deck, reviewedCardIDs)
now := time.Now() now := time.Now()
for _, card := range cards { for _, card := range cards {
blockID := card.BlockID() blockID := card.BlockID()
@ -442,10 +442,10 @@ func getDueFlashcards(deckID string) (ret []*Flashcard) {
return return
} }
func getAllDueFlashcards() (ret []*Flashcard) { func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard) {
now := time.Now() now := time.Now()
for _, deck := range Decks { for _, deck := range Decks {
cards := getDeckDueCards(deck) cards := getDeckDueCards(deck, reviewedCardIDs)
for _, card := range cards { for _, card := range cards {
blockID := card.BlockID() blockID := card.BlockID()
if nil == treenode.GetBlockTree(blockID) { if nil == treenode.GetBlockTree(blockID) {
@ -894,7 +894,7 @@ func getDeckIDs() (deckIDs []string) {
return return
} }
func getDeckDueCards(deck *riff.Deck) (ret []riff.Card) { func getDeckDueCards(deck *riff.Deck, reviewedCardIDs []string) (ret []riff.Card) {
ret = []riff.Card{} ret = []riff.Card{}
dues := deck.Dues() dues := deck.Dues()
@ -918,6 +918,10 @@ func getDeckDueCards(deck *riff.Deck) (ret []riff.Card) {
} }
} }
if !gulu.Str.Contains(c.ID(), reviewedCardIDs) {
continue
}
ret = append(ret, c) ret = append(ret, c)
} }
return return