feat: when removing a tag, remove descendants as well

This commit is contained in:
Antonella Sgarlatta
2021-06-14 14:11:54 -03:00
parent b0b9c30f27
commit b036174d11
2 changed files with 20 additions and 9 deletions

View File

@@ -198,9 +198,15 @@ export class NoteTagsState {
async removeTagFromActiveNote(tag: SNTag): Promise<void> { async removeTagFromActiveNote(tag: SNTag): Promise<void> {
const { activeNote } = this; const { activeNote } = this;
if (activeNote) { if (activeNote) {
await this.application.changeItem(tag.uuid, (mutator) => { const descendantTags = this.application.getTagDescendants(tag);
mutator.removeItemAsRelationship(activeNote); const tagsToRemove = [...descendantTags, tag];
}); await Promise.all(
tagsToRemove.map(async (tag) => {
await this.application.changeItem(tag.uuid, (mutator) => {
mutator.removeItemAsRelationship(activeNote);
});
})
);
this.application.sync(); this.application.sync();
this.reloadTags(); this.reloadTags();
} }

View File

@@ -346,13 +346,18 @@ export class NotesState {
async removeTagFromSelectedNotes(tag: SNTag): Promise<void> { async removeTagFromSelectedNotes(tag: SNTag): Promise<void> {
const selectedNotes = Object.values(this.selectedNotes); const selectedNotes = Object.values(this.selectedNotes);
await this.application.changeItem(tag.uuid, (mutator) => { const descendantTags = this.application.getTagDescendants(tag);
for (const note of selectedNotes) { const tagsToRemove = [...descendantTags, tag];
mutator.removeItemAsRelationship(note); await Promise.all(
} tagsToRemove.map(async (tag) => {
}); await this.application.changeItem(tag.uuid, (mutator) => {
for (const note of selectedNotes) {
mutator.removeItemAsRelationship(note);
}
});
})
);
this.application.sync(); this.application.sync();
} }
isTagInSelectedNotes(tag: SNTag): boolean { isTagInSelectedNotes(tag: SNTag): boolean {