Compare commits
1 Commits
3c47915755
...
f62c30da48
| Author | SHA1 | Date | |
|---|---|---|---|
|
f62c30da48
|
@@ -13,6 +13,14 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn sort_loader_result<T: Ord + Clone>(result: &mut Result<Loader<Vec<T>>, Loading>) {
|
||||||
|
if let Ok(items) = result.as_mut() {
|
||||||
|
let mut items_sorted = items();
|
||||||
|
items_sorted.sort();
|
||||||
|
items.set(items_sorted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
fn use_loader_with_update_subscription<F, T, E>(
|
fn use_loader_with_update_subscription<F, T, E>(
|
||||||
mut future: impl FnMut() -> F + 'static,
|
mut future: impl FnMut() -> F + 'static,
|
||||||
@@ -41,21 +49,25 @@ where
|
|||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
pub(crate) fn use_projects() -> Result<Loader<Vec<Project>>, Loading> {
|
pub(crate) fn use_projects() -> Result<Loader<Vec<Project>>, Loading> {
|
||||||
use_loader_with_update_subscription(get_projects).inspect(|projects| projects().sort())
|
let mut result = use_loader_with_update_subscription(get_projects);
|
||||||
|
sort_loader_result(&mut result);
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
pub(crate) fn use_tasks_with_subtasks_in_category(
|
pub(crate) fn use_tasks_with_subtasks_in_category(
|
||||||
filtered_category: Category,
|
filtered_category: Category,
|
||||||
) -> Result<Loader<Vec<TaskWithSubtasks>>, Loading> {
|
) -> Result<Loader<Vec<TaskWithSubtasks>>, Loading> {
|
||||||
use_loader_with_update_subscription(move || {
|
let mut result = use_loader_with_update_subscription(move || {
|
||||||
get_tasks_with_subtasks_in_category(filtered_category.clone())
|
get_tasks_with_subtasks_in_category(filtered_category.clone())
|
||||||
})
|
});
|
||||||
.inspect(|tasks| tasks().sort())
|
sort_loader_result(&mut result);
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
pub(crate) fn use_subtasks_of_task(task_id: i32) -> Result<Loader<Vec<Subtask>>, Loading> {
|
pub(crate) fn use_subtasks_of_task(task_id: i32) -> Result<Loader<Vec<Subtask>>, Loading> {
|
||||||
use_loader_with_update_subscription(move || get_subtasks_of_task(task_id))
|
let mut result = use_loader_with_update_subscription(move || get_subtasks_of_task(task_id));
|
||||||
.inspect(|subtasks| subtasks().sort())
|
sort_loader_result(&mut result);
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user