]> git.scottworley.com Git - vopamoi/commitdiff
Factor insertInPriorityOrder() out of setPriority()
authorScott Worley <scottworley@scottworley.com>
Tue, 1 Mar 2022 23:47:39 +0000 (15:47 -0800)
committerScott Worley <scottworley@scottworley.com>
Wed, 2 Mar 2022 00:02:35 +0000 (16:02 -0800)
vopamoi.ts

index 6ba608a4478481fbfcd6fb06f506f5b3ac439fbe..bdc8b0d2bf9acffb6bb34416b7fa165ea0227a26 100644 (file)
@@ -120,6 +120,17 @@ const Model = {
     }
   },
 
     }
   },
 
+  insertInPriorityOrder: function (task: Element, dest: Element) {
+    const priority = this.getPriority(task);
+    for (const t of dest.children) {
+      if (t !== task && this.getPriority(t) < priority) {
+        dest.insertBefore(task, t);
+        return;
+      }
+    }
+    dest.appendChild(task);
+  },
+
   removeTag: function (createTimestamp: string, tagName: string) {
     const task = this.getTask(createTimestamp);
     if (!task) return null;
   removeTag: function (createTimestamp: string, tagName: string) {
     const task = this.getTask(createTimestamp);
     if (!task) return null;
@@ -133,13 +144,7 @@ const Model = {
     const target = this.getTask(createTimestamp);
     if (!target) return null;
     target.setAttribute("data-priority", `${priority}`);
     const target = this.getTask(createTimestamp);
     if (!target) return null;
     target.setAttribute("data-priority", `${priority}`);
-    for (const task of document.getElementsByClassName("task")) {
-      if (task !== target && this.getPriority(task) < priority) {
-        task.parentElement!.insertBefore(target, task);
-        return target;
-      }
-    }
-    document.getElementById("tasks")!.appendChild(target);
+    this.insertInPriorityOrder(target, target.parentElement!);
     return target;
   },
 
     return target;
   },