]> git.scottworley.com Git - vopamoi/commitdiff
Don't create duplicate tags; Tagging is idempotent
authorScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 20:02:27 +0000 (12:02 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 20:22:18 +0000 (12:22 -0800)
vopamoi.ts

index 7c51935a2c14535444199ddb68da35ec2eca4e17..3b2f1638beb180e3e6b294cfa59b23ee2c73fe3d 100644 (file)
@@ -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 {