mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 闪卡复习评分支持撤销 https://github.com/siyuan-note/siyuan/issues/7455
This commit is contained in:
parent
5b30b60bf7
commit
610afaddc7
6 changed files with 20 additions and 11 deletions
|
|
@ -174,6 +174,7 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
||||||
if (["0", "1", "2", "3"].includes(type)) {
|
if (["0", "1", "2", "3"].includes(type)) {
|
||||||
fetchPost("/api/riff/reviewRiffCard", {
|
fetchPost("/api/riff/reviewRiffCard", {
|
||||||
deckID: blocks[index].deckID,
|
deckID: blocks[index].deckID,
|
||||||
|
cardID: blocks[index].cardID,
|
||||||
blockID: blocks[index].blockID,
|
blockID: blocks[index].blockID,
|
||||||
rating: parseInt(type)
|
rating: parseInt(type)
|
||||||
}, () => {
|
}, () => {
|
||||||
|
|
|
||||||
3
app/src/types/index.d.ts
vendored
3
app/src/types/index.d.ts
vendored
|
|
@ -67,8 +67,9 @@ interface ICardPackage {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICard {
|
interface ICard {
|
||||||
blockID: string
|
|
||||||
deckID: string
|
deckID: string
|
||||||
|
cardID: string
|
||||||
|
blockID: string
|
||||||
nextDues: IObject
|
nextDues: IObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ func getRiffCards(c *gin.Context) {
|
||||||
|
|
||||||
deckID := arg["id"].(string)
|
deckID := arg["id"].(string)
|
||||||
page := int(arg["page"].(float64))
|
page := int(arg["page"].(float64))
|
||||||
blockIDs, total, pageCount := model.GetFlashcards(deckID, page)
|
blocks, total, pageCount := model.GetFlashcards(deckID, page)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"blocks": blockIDs,
|
"blocks": blocks,
|
||||||
"total": total,
|
"total": total,
|
||||||
"pageCount": pageCount,
|
"pageCount": pageCount,
|
||||||
}
|
}
|
||||||
|
|
@ -75,9 +75,10 @@ func reviewRiffCard(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
deckID := arg["deckID"].(string)
|
deckID := arg["deckID"].(string)
|
||||||
|
cardID := arg["cardID"].(string)
|
||||||
blockID := arg["blockID"].(string)
|
blockID := arg["blockID"].(string)
|
||||||
rating := int(arg["rating"].(float64))
|
rating := int(arg["rating"].(float64))
|
||||||
err := model.ReviewFlashcard(deckID, blockID, riff.Rating(rating))
|
err := model.ReviewFlashcard(deckID, cardID, blockID, riff.Rating(rating))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
@ -125,6 +126,7 @@ func getRiffDueCards(c *gin.Context) {
|
||||||
ret.Data = cards
|
ret.Data = cards
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 删除闪卡
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ require (
|
||||||
github.com/siyuan-note/filelock v0.0.0-20230223100551-200cbe1cf84e
|
github.com/siyuan-note/filelock v0.0.0-20230223100551-200cbe1cf84e
|
||||||
github.com/siyuan-note/httpclient v0.0.0-20230223101139-409ed0b4c5ff
|
github.com/siyuan-note/httpclient v0.0.0-20230223101139-409ed0b4c5ff
|
||||||
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb
|
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb
|
||||||
github.com/siyuan-note/riff v0.0.0-20230224070227-4514ccc3e496
|
github.com/siyuan-note/riff v0.0.0-20230224074237-c16f59420520
|
||||||
github.com/steambap/captcha v1.4.1
|
github.com/steambap/captcha v1.4.1
|
||||||
github.com/studio-b12/gowebdav v0.0.0-20230203202212-3282f94193f2
|
github.com/studio-b12/gowebdav v0.0.0-20230203202212-3282f94193f2
|
||||||
github.com/vmihailenco/msgpack/v5 v5.3.5
|
github.com/vmihailenco/msgpack/v5 v5.3.5
|
||||||
|
|
|
||||||
|
|
@ -286,8 +286,8 @@ github.com/siyuan-note/httpclient v0.0.0-20230223101139-409ed0b4c5ff h1:3G48J/tG
|
||||||
github.com/siyuan-note/httpclient v0.0.0-20230223101139-409ed0b4c5ff/go.mod h1:/fjYEiYPN2ZNR2zVTopobwzo3rOychV2qbsutxiV0jI=
|
github.com/siyuan-note/httpclient v0.0.0-20230223101139-409ed0b4c5ff/go.mod h1:/fjYEiYPN2ZNR2zVTopobwzo3rOychV2qbsutxiV0jI=
|
||||||
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb h1:qzz7ZQw7/tHJd1IST+8UymXFF8RacokMLD7VZgyS+ww=
|
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb h1:qzz7ZQw7/tHJd1IST+8UymXFF8RacokMLD7VZgyS+ww=
|
||||||
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
|
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
|
||||||
github.com/siyuan-note/riff v0.0.0-20230224070227-4514ccc3e496 h1:6u9vlE4EhRja4abccUPGNmG+aMBm/D+5lVomkoYuSmo=
|
github.com/siyuan-note/riff v0.0.0-20230224074237-c16f59420520 h1:14vDSmi+YYBCnPb41ESSaq8kzgx6Sj4fE1mNJQwVObw=
|
||||||
github.com/siyuan-note/riff v0.0.0-20230224070227-4514ccc3e496/go.mod h1:XJtLlKCr8cZE+lzykM4edHHih92M9M50UNw/nDLYRN8=
|
github.com/siyuan-note/riff v0.0.0-20230224074237-c16f59420520/go.mod h1:XJtLlKCr8cZE+lzykM4edHHih92M9M50UNw/nDLYRN8=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=
|
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount i
|
||||||
// reviewCardCache <cardID, card> 用于复习时缓存卡片,以便支持撤销。
|
// reviewCardCache <cardID, card> 用于复习时缓存卡片,以便支持撤销。
|
||||||
var reviewCardCache = map[string]riff.Card{}
|
var reviewCardCache = map[string]riff.Card{}
|
||||||
|
|
||||||
func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err error) {
|
func ReviewFlashcard(deckID, cardID, blockID string, rating riff.Rating) (err error) {
|
||||||
deckLock.Lock()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
|
||||||
|
|
@ -168,9 +168,9 @@ func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err err
|
||||||
}
|
}
|
||||||
|
|
||||||
deck := Decks[deckID]
|
deck := Decks[deckID]
|
||||||
card := deck.GetCard(blockID)
|
card := deck.GetCard(cardID)
|
||||||
if nil == card {
|
if nil == card {
|
||||||
logging.LogErrorf("card not found [%s]", blockID)
|
logging.LogErrorf("card not found [%s]", cardID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,7 +467,12 @@ func removeFlashcard(blockIDs []string, deck *riff.Deck) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, blockID := range blockIDs {
|
for _, blockID := range blockIDs {
|
||||||
deck.RemoveCard(blockID)
|
// TODO 这里的代码需要重构,要支持一个块对应多张卡
|
||||||
|
cardID := deck.BlockCard[blockID]
|
||||||
|
if "" == cardID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
deck.RemoveCard(cardID)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := deck.Save()
|
err := deck.Save()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue