🎨 支持在 All 卡包中移除闪卡 Fix https://github.com/siyuan-note/siyuan/issues/7425

This commit is contained in:
Liang Ding 2023-02-21 10:15:57 +08:00
parent bb0776bd38
commit 740761fcc8
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -379,9 +379,11 @@ func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
deckAttrs := node.IALAttr("custom-riff-decks")
var deckIDs []string
for _, dID := range strings.Split(deckAttrs, ",") {
if dID != deckID && gulu.Str.Contains(dID, availableDeckIDs) {
deckIDs = append(deckIDs, dID)
if "" != deckID {
for _, dID := range strings.Split(deckAttrs, ",") {
if dID != deckID && gulu.Str.Contains(dID, availableDeckIDs) {
deckIDs = append(deckIDs, dID)
}
}
}
@ -410,20 +412,32 @@ func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
pushBroadcastAttrTransactions(trans)
}
deck := Decks[deckID]
if nil != deck {
for _, blockID := range blockIDs {
deck.RemoveCard(blockID)
}
err = deck.Save()
if nil != err {
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
return
if "" == deckID { // 支持在 All 卡包中移除闪卡 https://github.com/siyuan-note/siyuan/issues/7425
for _, deck := range Decks {
removeFlashcard(blockIDs, deck)
}
} else {
removeFlashcard(blockIDs, Decks[deckID])
}
return
}
func removeFlashcard(blockIDs []string, deck *riff.Deck) {
if nil == deck {
logging.LogErrorf("deck is nil")
return
}
for _, blockID := range blockIDs {
deck.RemoveCard(blockID)
}
err := deck.Save()
if nil != err {
logging.LogErrorf("save deck [%s] failed: %s", deck.ID, err)
}
}
func AddFlashcards(deckID string, blockIDs []string) (err error) {
deckLock.Lock()
defer deckLock.Unlock()