From 3916a89c8a391d43c8160409862bcba18259f659 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 27 Jan 2022 12:02:27 -0800 Subject: [PATCH] Don't create duplicate tags; Tagging is idempotent --- vopamoi.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 { -- 2.44.1