feat: display a project form upon clicking the create button on the projects page
This commit is contained in:
@ -1,13 +1,16 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::project::Project;
|
||||
use crate::models::task::Task;
|
||||
|
||||
pub(crate) mod tasks;
|
||||
pub(crate) mod projects;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub(crate) enum QueryValue {
|
||||
Tasks(Vec<Task>),
|
||||
Projects(Vec<Project>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -19,4 +22,5 @@ pub(crate) enum QueryErrors {
|
||||
pub(crate) enum QueryKey {
|
||||
Tasks,
|
||||
TasksInCategory(Category),
|
||||
Projects,
|
||||
}
|
||||
|
20
src/query/projects.rs
Normal file
20
src/query/projects.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::server::projects::get_projects;
|
||||
use dioxus::prelude::ServerFnError;
|
||||
use dioxus_query::prelude::{use_get_query, QueryResult, UseQuery};
|
||||
|
||||
pub(crate) fn use_projects_query() -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||
use_get_query([QueryKey::Projects, QueryKey::Tasks], fetch_projects)
|
||||
}
|
||||
|
||||
async fn fetch_projects(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
||||
if let Some(QueryKey::Projects) = keys.first() {
|
||||
match get_projects().await {
|
||||
Ok(projects) => Ok(QueryValue::Projects(projects)),
|
||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||
Err(error) => panic!("Unexpected error: {:?}", error)
|
||||
}.into()
|
||||
} else {
|
||||
panic!("Unexpected query keys: {:?}", keys);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user