Hide note editor on blur when text is empty
Assisted-by: Claude Opus 4.6 via Claude Code
change kqwwnlzpvvkuqzzpnwrlmwwztozrltxk
commit 7b820ac5f19661ef8a4c161d86221806492c0d02
author Alpha Chen <alpha@kejadlen.dev>
date
parent mqrmzmls
diff --git a/lib/ketchup/views/dashboard.rb b/lib/ketchup/views/dashboard.rb
index 09209a2..fe79274 100644
--- a/lib/ketchup/views/dashboard.rb
+++ b/lib/ketchup/views/dashboard.rb
@@ -154,7 +154,8 @@ module Views
                           class: "task-history-add-note",
                           "x-data": "{ adding: false }",
                           "x-show": "!adding",
-                          "x-on:click": "adding = true; $dispatch('add-note-#{ct[:id]}')"
+                          "x-on:click": "adding = true; $dispatch('add-note-#{ct[:id]}')",
+                          "x-on:reset-note-#{ct[:id]}.window": "adding = false"
                         ) { "add a note..." }
                       end
                     end
diff --git a/public/js/app.js b/public/js/app.js
index bc5c51d..eb660f8 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -136,6 +136,20 @@ document.addEventListener("alpine:init", () => {
         if (!initialNote) textarea.focus()
         textarea.addEventListener("blur", () => {
           const note = editor.getValue().trim()
+
+          if (!note) {
+            if (initialNote) {
+              fetch(`/tasks/${taskId}/note`, {
+                method: "PATCH",
+                headers: { "Content-Type": "application/x-www-form-urlencoded" },
+                body: `note=`,
+              })
+            }
+            el.style.display = "none"
+            window.dispatchEvent(new Event(`reset-note-${taskId}`))
+            return
+          }
+
           if (note === (initialNote || "").trim()) return
 
           el.dataset.value = note