Skip to content

Commit

Permalink
🛠 fix issue with tag deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragnar-Oock committed Nov 11, 2019
1 parent c9f6688 commit b37756f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions music.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ class Music {
// loop through an image of the list and delete all tags that are not present anymore
for (let i = 0, len = tagList.length; i < len; i++) {
const currentTag = tagList[i];
// get the index of the tag in obj
let objTagIndex = obj.findIndex(function (tag) {
return tag.id === currentTag.id;
})
if (objTagIndex === -1) {
this.tags[i].delete();
this.tags.splice(i, 1);
// visualy delete the tag
currentTag.delete();
// get the index of the tag in the tag list
let index = this.tags.findIndex(function (tag) {
return tag.id === currentTag.id;
})
// pop the tag of the list
this.tags.splice(index, 1);
}
}
// loop througth all the tag of the received obj
Expand All @@ -186,17 +193,19 @@ class Music {
// if the current tag is not present add it
if (tagIndex === -1) {
let tag = new Tag(objTag, this.id, i),
tagList = this.dom.children().eq(0);
tagWrapper = this.dom.children().eq(0),
tagWrapperLen = tagWrapper.children().length;

// add the tag to this.tags
this.tags.splice(i, 0, tag);
// add the new tag object to the list at the good index
if (0 <= i && i < len) {
if (0 <= i && i < tagWrapperLen) {
// insert the tag before the i-th tag
tagList.children().eq(i).before(tag.toHtml());
tagWrapper.children().eq(i).before(tag.toHtml());
}
else {
// insert the tag at the end of the list
tagList.append(tag.toHtml());
tagWrapper.append(tag.toHtml());
}
// update the parent with the tag's custom class
tag.updateParentClass();
Expand Down Expand Up @@ -226,4 +235,4 @@ class Music {
this.tags = [];
}
}
}
}

0 comments on commit b37756f

Please sign in to comment.