diff --git a/src/components/category_calendar_task_list.rs b/src/components/category_calendar_task_list.rs index fda7909..8ddb407 100644 --- a/src/components/category_calendar_task_list.rs +++ b/src/components/category_calendar_task_list.rs @@ -19,7 +19,7 @@ pub(crate) fn CategoryCalendarTaskList() -> Element { date: today_date, reoccurrence: None, time: None, - })?(); + })?; rsx! { div { diff --git a/src/components/category_today_task_list.rs b/src/components/category_today_task_list.rs index fd4e504..49e992f 100644 --- a/src/components/category_today_task_list.rs +++ b/src/components/category_today_task_list.rs @@ -17,7 +17,7 @@ pub(crate) fn CategoryTodayTaskList() -> Element { date: today_date, reoccurrence: None, time: None, - })?(); + })?; let today_tasks = calendar_tasks .iter() .filter(|task| { @@ -40,7 +40,7 @@ pub(crate) fn CategoryTodayTaskList() -> Element { }) .cloned() .collect::>(); - let long_term_tasks = use_tasks_with_subtasks_in_category(Category::LongTerm)?(); + let long_term_tasks = use_tasks_with_subtasks_in_category(Category::LongTerm)?; rsx! { div { diff --git a/src/components/project_list.rs b/src/components/project_list.rs index ab4924c..e550e98 100644 --- a/src/components/project_list.rs +++ b/src/components/project_list.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; #[component] pub(crate) fn ProjectList() -> Element { - let projects = use_projects()?(); + let projects = use_projects()?; let mut project_being_edited = use_context::>>(); rsx! { diff --git a/src/components/project_select.rs b/src/components/project_select.rs index a83d101..fc3021e 100644 --- a/src/components/project_select.rs +++ b/src/components/project_select.rs @@ -6,7 +6,7 @@ use dioxus_i18n::t; #[component] pub(crate) fn ProjectSelect(initial_selected_id: Option) -> Element { - let projects = use_projects()?(); + let projects = use_projects()?; rsx! { select { name: "project_id", diff --git a/src/components/subtasks_form.rs b/src/components/subtasks_form.rs index 302fd3c..e488014 100644 --- a/src/components/subtasks_form.rs +++ b/src/components/subtasks_form.rs @@ -8,7 +8,7 @@ use dioxus::prelude::*; #[component] pub(crate) fn SubtasksForm(task: Task) -> Element { - let subtasks = use_subtasks_of_task(task.id)?(); + let subtasks = use_subtasks_of_task(task.id)?; let mut new_title = use_signal(String::new); rsx! { form { diff --git a/src/components/task_list.rs b/src/components/task_list.rs index 8c6dd62..b724852 100644 --- a/src/components/task_list.rs +++ b/src/components/task_list.rs @@ -1,6 +1,7 @@ use crate::components::task_list_item::TaskListItem; use crate::models::category::Category; use crate::models::task::{Task, TaskWithSubtasks}; +use crate::server::tasks::complete_task; use dioxus::core_macro::rsx; use dioxus::dioxus_core::Element; use dioxus::prelude::*; @@ -48,6 +49,9 @@ pub(crate) fn TaskList(tasks: Vec, class: Option<&'static str> move |event: Event| { // To prevent editing the task. event.stop_propagation(); + async move { + let _ = complete_task(task.task.id).await; + } } } }, diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index 27b6209..89e3355 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -13,6 +13,17 @@ use crate::{ }, }; +#[allow(clippy::result_large_err)] +fn sort_loader_result( + result: Result>, Loading>, +) -> Result, Loading> { + result.map(|loader| { + let mut items_sorted = loader(); + items_sorted.sort(); + items_sorted + }) +} + #[allow(clippy::result_large_err)] fn use_loader_with_update_subscription( mut future: impl FnMut() -> F + 'static, @@ -40,22 +51,23 @@ where } #[allow(clippy::result_large_err)] -pub(crate) fn use_projects() -> Result>, Loading> { - use_loader_with_update_subscription(get_projects).inspect(|projects| projects().sort()) +pub(crate) fn use_projects() -> Result, Loading> { + let result = use_loader_with_update_subscription(get_projects); + sort_loader_result(result) } #[allow(clippy::result_large_err)] pub(crate) fn use_tasks_with_subtasks_in_category( filtered_category: Category, -) -> Result>, Loading> { - use_loader_with_update_subscription(move || { +) -> Result, Loading> { + let result = use_loader_with_update_subscription(move || { get_tasks_with_subtasks_in_category(filtered_category.clone()) - }) - .inspect(|tasks| tasks().sort()) + }); + sort_loader_result(result) } #[allow(clippy::result_large_err)] -pub(crate) fn use_subtasks_of_task(task_id: i32) -> Result>, Loading> { - use_loader_with_update_subscription(move || get_subtasks_of_task(task_id)) - .inspect(|subtasks| subtasks().sort()) +pub(crate) fn use_subtasks_of_task(task_id: i32) -> Result, Loading> { + let result = use_loader_with_update_subscription(move || get_subtasks_of_task(task_id)); + sort_loader_result(result) } diff --git a/src/views/category_page.rs b/src/views/category_page.rs index b80a395..64fb8e3 100644 --- a/src/views/category_page.rs +++ b/src/views/category_page.rs @@ -7,7 +7,7 @@ use dioxus::prelude::*; #[component] pub(crate) fn CategoryPage(category: Category) -> Element { - let tasks = use_tasks_with_subtasks_in_category(category)?(); + let tasks = use_tasks_with_subtasks_in_category(category)?; rsx! { TaskList {