chore: upgrade to Dioxus 0.7
All checks were successful
actionlint check / actionlint check (pull_request) Successful in 5s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 5s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 10s
hadolint check / hadolint check (pull_request) Successful in 16s
GitLeaks check / GitLeaks check (pull_request) Successful in 10s
htmlhint check / htmlhint check (pull_request) Successful in 35s
Prettier check / Prettier check (pull_request) Successful in 26s
markdownlint check / markdownlint check (pull_request) Successful in 31s
checkov check / checkov check (pull_request) Successful in 1m15s
ShellCheck check / ShellCheck check (pull_request) Successful in 30s
Stylelint check / Stylelint check (pull_request) Successful in 29s
yamllint check / yamllint check (pull_request) Successful in 27s
Rust check / Rust check (pull_request) Successful in 11m44s
All checks were successful
actionlint check / actionlint check (pull_request) Successful in 5s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 5s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 10s
hadolint check / hadolint check (pull_request) Successful in 16s
GitLeaks check / GitLeaks check (pull_request) Successful in 10s
htmlhint check / htmlhint check (pull_request) Successful in 35s
Prettier check / Prettier check (pull_request) Successful in 26s
markdownlint check / markdownlint check (pull_request) Successful in 31s
checkov check / checkov check (pull_request) Successful in 1m15s
ShellCheck check / ShellCheck check (pull_request) Successful in 30s
Stylelint check / Stylelint check (pull_request) Successful in 29s
yamllint check / yamllint check (pull_request) Successful in 27s
Rust check / Rust check (pull_request) Successful in 11m44s
This commit is contained in:
61
src/hooks/mod.rs
Normal file
61
src/hooks/mod.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use dioxus::{
|
||||
CapturedError,
|
||||
fullstack::{Loader, Loading, WebSocketOptions, use_websocket},
|
||||
prelude::*,
|
||||
};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
|
||||
use crate::{
|
||||
models::{category::Category, project::Project, subtask::Subtask, task::TaskWithSubtasks},
|
||||
server::{
|
||||
projects::get_projects, subtasks::get_subtasks_of_task,
|
||||
tasks::get_tasks_with_subtasks_in_category, updates::subscribe_to_updates,
|
||||
},
|
||||
};
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
fn use_loader_with_update_subscription<F, T, E>(
|
||||
mut future: impl FnMut() -> F + 'static,
|
||||
) -> Result<Loader<T>, Loading>
|
||||
where
|
||||
F: Future<Output = Result<T, E>> + 'static,
|
||||
T: 'static + PartialEq + Serialize + DeserializeOwned,
|
||||
E: Into<CapturedError> + 'static,
|
||||
{
|
||||
let mut refresh_tick = use_signal(|| 0u64);
|
||||
|
||||
let loader = use_loader(move || {
|
||||
let _ = refresh_tick(); // Read => dependency.
|
||||
future()
|
||||
});
|
||||
|
||||
let mut socket = use_websocket(|| subscribe_to_updates(WebSocketOptions::default()));
|
||||
use_future(move || async move {
|
||||
while socket.recv().await.is_ok() {
|
||||
refresh_tick += 1;
|
||||
}
|
||||
});
|
||||
|
||||
loader
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub(crate) fn use_projects() -> Result<Loader<Vec<Project>>, Loading> {
|
||||
use_loader_with_update_subscription(get_projects).inspect(|projects| projects().sort())
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub(crate) fn use_tasks_with_subtasks_in_category(
|
||||
filtered_category: Category,
|
||||
) -> Result<Loader<Vec<TaskWithSubtasks>>, Loading> {
|
||||
use_loader_with_update_subscription(move || {
|
||||
get_tasks_with_subtasks_in_category(filtered_category.clone())
|
||||
})
|
||||
.inspect(|tasks| tasks().sort())
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
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))
|
||||
.inspect(|subtasks| subtasks().sort())
|
||||
}
|
||||
Reference in New Issue
Block a user