From 7ac3c6e136959a00d7ea3f066e36aa5f655c596c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Volf?= <66163112+matous-volf@users.noreply.github.com> Date: Sun, 8 Sep 2024 09:56:37 +0200 Subject: [PATCH] feat: add the ability to delete a task --- src/components/task_form.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/components/task_form.rs b/src/components/task_form.rs index d0bc46b..8618c48 100644 --- a/src/components/task_form.rs +++ b/src/components/task_form.rs @@ -6,7 +6,7 @@ use crate::models::task::Task; use crate::query::{QueryErrors, QueryKey, QueryValue}; use crate::route::Route; use crate::server::projects::get_projects; -use crate::server::tasks::{create_task, edit_task}; +use crate::server::tasks::{create_task, delete_task, edit_task}; use chrono::{Duration}; use dioxus::core_macro::{component, rsx}; use dioxus::dioxus_core::Element; @@ -336,7 +336,39 @@ pub(crate) fn TaskForm(task: Option, on_successful_submit: EventHandler<() _ => None }, div { - class: "flex flex-row justify-end mt-auto", + class: "flex flex-row justify-between mt-auto", + button { + r#type: "button", + class: "py-2 px-4 bg-zinc-300/50 rounded-lg", + onclick: move |_| { + let task = task.clone(); + async move { + if let Some(task) = task { + if *(task.category()) == Category::Trash { + let _ = delete_task(task.id()).await; + } else { + let new_task = NewTask::new( + task.title().to_owned(), + task.deadline(), + Category::Trash, + task.project_id() + ); + + let _ = edit_task(task.id(), new_task).await; + } + + query_client.invalidate_queries(&[ + QueryKey::TasksInCategory(task.category().clone()), + QueryKey::Tasks, + ]); + } + on_successful_submit.call(()); + } + }, + i { + class: "fa-solid fa-trash-can" + } + } button { r#type: "submit", class: "py-2 px-4 bg-zinc-300/50 rounded-lg",