feat(tasks): refine enhanced task linking, outliner badge positioning, completion sync and unlink behavior
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 59s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 59s
This commit is contained in:
1 parent
6129681035
commit
5cf6b59377
5 files changed
+139
-60
No files matched your search
+44
-16
@@ -2404,6 +2404,29 @@ func (s *Store) UpdateDocument(userID, docID string, title, icon, folderPath *st
|
||||
s.SyncTaskFromBlockCheck(doc.UserID, b.TaskID, b.Checked)
|
||||
}
|
||||
}
|
||||
|
||||
// When a block is deleted from the note, unlink the corresponding task in thoughts without deleting the task
|
||||
remainingBlockIDs := make(map[string]bool)
|
||||
for _, b := range doc.Blocks {
|
||||
remainingBlockIDs[b.ID] = true
|
||||
}
|
||||
rows, err := s.db.Query(`SELECT id, converted_ref_id, block_id FROM thoughts WHERE (doc_id = ? OR converted_ref_id LIKE ?) AND converted_type = 'document_block'`, docID, docID+":%")
|
||||
if err == nil {
|
||||
for rows.Next() {
|
||||
var tid, refID, bID string
|
||||
if err := rows.Scan(&tid, &refID, &bID); err == nil {
|
||||
bid := bID
|
||||
if bid == "" && strings.Contains(refID, ":") {
|
||||
parts := strings.SplitN(refID, ":", 2)
|
||||
bid = parts[1]
|
||||
}
|
||||
if !remainingBlockIDs[bid] {
|
||||
_, _ = s.db.Exec(`UPDATE thoughts SET converted_type = '', converted_ref_id = '', doc_id = '', block_id = '' WHERE id = ?`, tid)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = rows.Close()
|
||||
}
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
@@ -4239,27 +4262,32 @@ func (s *Store) SyncDocBlockAndTask(userID, taskID string, isCompleted bool) {
|
||||
|
||||
func (s *Store) UnlinkTaskFromDocBlock(userID, taskID string) {
|
||||
t, err := s.GetThoughtByID(userID, taskID)
|
||||
if err != nil || t == nil || t.ConvertedType != "document_block" || !strings.Contains(t.ConvertedRefID, ":") {
|
||||
if err != nil || t == nil {
|
||||
return
|
||||
}
|
||||
parts := strings.SplitN(t.ConvertedRefID, ":", 2)
|
||||
docID, blockID := parts[0], parts[1]
|
||||
doc, err := s.GetDocumentByID(userID, docID)
|
||||
if err != nil || doc == nil {
|
||||
return
|
||||
docID := t.DocID
|
||||
blockID := t.BlockID
|
||||
if (docID == "" || blockID == "") && strings.Contains(t.ConvertedRefID, ":") {
|
||||
parts := strings.SplitN(t.ConvertedRefID, ":", 2)
|
||||
docID, blockID = parts[0], parts[1]
|
||||
}
|
||||
var updatedBlocks []domain.DocumentBlock
|
||||
found := false
|
||||
for _, b := range doc.Blocks {
|
||||
if b.ID == blockID {
|
||||
b.TaskID = ""
|
||||
found = true
|
||||
if docID != "" {
|
||||
if doc, err := s.GetDocumentByID(userID, docID); err == nil && doc != nil {
|
||||
var updatedBlocks []domain.DocumentBlock
|
||||
found := false
|
||||
for _, b := range doc.Blocks {
|
||||
if b.ID == blockID || b.TaskID == taskID {
|
||||
b.TaskID = ""
|
||||
found = true
|
||||
}
|
||||
updatedBlocks = append(updatedBlocks, b)
|
||||
}
|
||||
if found {
|
||||
_, _ = s.UpdateDocument(userID, docID, nil, nil, nil, &updatedBlocks, nil, nil)
|
||||
}
|
||||
}
|
||||
updatedBlocks = append(updatedBlocks, b)
|
||||
}
|
||||
if found {
|
||||
_, _ = s.UpdateDocument(userID, docID, nil, nil, nil, &updatedBlocks, nil, nil)
|
||||
}
|
||||
_, _ = s.db.Exec(`UPDATE thoughts SET converted_type = '', converted_ref_id = '', doc_id = '', block_id = '' WHERE id = ?`, taskID)
|
||||
}
|
||||
|
||||
func (s *Store) SyncTaskFromBlockCheck(userID, taskID string, checked bool) {
|
||||
|
||||
Reference in new issue
Block a user