]> git.scottworley.com Git - vopamoi/commitdiff
Don't attempt to create duplicate tags
authorScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 19:59:03 +0000 (11:59 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 20:22:18 +0000 (12:22 -0800)
vopamoi.ts

index 5ac82ef516854c12232026753594d8686fbc0db7..7c51935a2c14535444199ddb68da35ec2eca4e17 100644 (file)
@@ -77,6 +77,15 @@ const Model = {
     return target;
   },
 
     return target;
   },
 
+  hasTag: function (task: Element, tag: string) {
+    for (const child of task.children) {
+      if (child.classList.contains("tag") && child.textContent === tag) {
+        return true;
+      }
+    }
+    return false;
+  },
+
   getPriority: function (task: Element): number {
     if (task.hasAttribute("data-priority")) {
       return parseFloat(task.getAttribute("data-priority")!);
   getPriority: function (task: Element): number {
     if (task.hasAttribute("data-priority")) {
       return parseFloat(task.getAttribute("data-priority")!);
@@ -270,7 +279,9 @@ function BrowserUI() {
       input.removeEventListener("blur", this.completeTagEdit);
       task.removeChild(input);
       task.focus();
       input.removeEventListener("blur", this.completeTagEdit);
       task.removeChild(input);
       task.focus();
-      ui.addTag(task.getAttribute("data-created")!, newTagName);
+      if (!Model.hasTag(task, newTagName)) {
+        ui.addTag(task.getAttribute("data-created")!, newTagName);
+      }
     },
 
     firstVisibleTask: function () {
     },
 
     firstVisibleTask: function () {