From: Scott Worley Date: Thu, 27 Jan 2022 20:02:27 +0000 (-0800) Subject: Don't create duplicate tags; Tagging is idempotent X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/3916a89c8a391d43c8160409862bcba18259f659 Don't create duplicate tags; Tagging is idempotent --- diff --git a/vopamoi.ts b/vopamoi.ts index 7c51935..3b2f163 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -44,6 +44,8 @@ const Model = { 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"); @@ -77,13 +79,13 @@ const Model = { 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 {