From fbef0cbeba1e4eed1019fcadb3bfd93d90918109 Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 25 Apr 2023 06:19:59 -0400 Subject: [PATCH] added deletion of project from projects table on success. --- src/components/admin_project.rs | 6 ++++-- src/pages/admin/edit.rs | 3 +-- src/pages/admin/projects.rs | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/admin_project.rs b/src/components/admin_project.rs index db09e3a..e8a4837 100644 --- a/src/components/admin_project.rs +++ b/src/components/admin_project.rs @@ -16,13 +16,15 @@ pub fn admin_project(props: &AdminProjectProps) -> Html { let is_attempting_delete = is_attempting_delete.clone(); let project_id = props.project.id.clone(); let force_update_handle = props.forceupdate.clone(); + let index = props.index; Callback::from(move |event: MouseEvent| { if *is_attempting_delete { let project_id = project_id.clone(); let force_update_handle = force_update_handle.clone(); + let index = index.clone(); wasm_bindgen_futures::spawn_local(async move { match delete_project(&project_id).await { - Ok(_) => {force_update_handle.emit(())}, + Ok(_) => {force_update_handle.emit(index)}, Err(error) => {log::error!("Error deleting project: {error}")} }; }); @@ -77,5 +79,5 @@ pub fn admin_project(props: &AdminProjectProps) -> Html { pub struct AdminProjectProps { pub project: ProjectCardDto, pub index: usize, - pub forceupdate: Callback<()>, + pub forceupdate: Callback, } diff --git a/src/pages/admin/edit.rs b/src/pages/admin/edit.rs index 8c94996..8027967 100644 --- a/src/pages/admin/edit.rs +++ b/src/pages/admin/edit.rs @@ -262,8 +262,6 @@ pub fn generate_fields_for_project(props: &ProjectFieldsProps) -> Html { Callback::from(move |_: MouseEvent| { let navigator = navigator.clone(); let edit_type = edit_type.clone(); - //TODO: Create the location first. - //TODO: Then send the updateprojectpayload. let location_city_handle = location_city.clone(); let location_district_handle = location_district.clone(); let agent_handle = agent.clone(); @@ -299,6 +297,7 @@ pub fn generate_fields_for_project(props: &ProjectFieldsProps) -> Html { } } }; + //TODO: Give all of these default values? let agent_id = match (*agent_handle).clone() { Some(selected_agent) => selected_agent.id, None => { diff --git a/src/pages/admin/projects.rs b/src/pages/admin/projects.rs index 9876b85..ee4f61a 100644 --- a/src/pages/admin/projects.rs +++ b/src/pages/admin/projects.rs @@ -11,7 +11,6 @@ use crate::{ #[function_component(AdminProjects)] pub fn admin_projects() -> Html { let projects = use_state(|| Vec::new()); - let force_update_handle = use_force_update(); use_state(|| { let projects_handle = projects.clone(); wasm_bindgen_futures::spawn_local(async move { @@ -38,9 +37,11 @@ pub fn admin_projects() -> Html { {(*projects).clone().into_iter().enumerate().map(|(key, project)| html! { <>