From c0fa65515794f82bf5605c290274ccde19c6c299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Volf?= Date: Mon, 9 Sep 2024 08:41:57 +0200 Subject: [PATCH] fix: handle changing a subtask's title to empty --- src/components/subtasks_form.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/subtasks_form.rs b/src/components/subtasks_form.rs index 29fb00f..3e16e28 100644 --- a/src/components/subtasks_form.rs +++ b/src/components/subtasks_form.rs @@ -109,7 +109,7 @@ pub(crate) fn SubtasksForm(task: Task) -> Element { input { r#type: "text", class: "grow py-2 px-3 col-span-5 bg-zinc-800/50 rounded-lg", - id: "input_new_title", + id: "input_title_{subtask.id()}", initial_value: subtask.title(), onchange: { let subtask = subtask.clone(); @@ -123,10 +123,14 @@ pub(crate) fn SubtasksForm(task: Task) -> Element { event.value(), subtask.is_completed() ); - let _ = edit_subtask( - subtask.id(), - new_subtask - ).await; + if new_subtask.title.is_empty() { + let _ = delete_subtask(subtask.id()).await; + } else { + let _ = edit_subtask( + subtask.id(), + new_subtask + ).await; + } query_client.invalidate_queries(&[ QueryKey::SubtasksOfTaskId(task.id()), QueryKey::TasksWithSubtasksInCategory(