addTag: function (createTimestamp: string, tagName: string): Element | null {
const task = this.getTask(createTimestamp);
if (!task) return null;
+ const existingTag = this.hasTag(task, tagName);
+ if (existingTag) return existingTag;
const tag = document.createElement("span");
tag.appendChild(document.createTextNode(tagName));
tag.classList.add("tag");
return target;
},
- hasTag: function (task: Element, tag: string) {
+ hasTag: function (task: Element, tag: string): Element | null {
for (const child of task.children) {
if (child.classList.contains("tag") && child.textContent === tag) {
- return true;
+ return child;
}
}
- return false;
+ return null;
},
getPriority: function (task: Element): number {