added deletion of project from projects table on success.

This commit is contained in:
Franklin 2023-04-25 06:19:59 -04:00
parent ba1a954537
commit fbef0cbeba
3 changed files with 10 additions and 8 deletions

View File

@ -16,13 +16,15 @@ pub fn admin_project(props: &AdminProjectProps) -> Html {
let is_attempting_delete = is_attempting_delete.clone(); let is_attempting_delete = is_attempting_delete.clone();
let project_id = props.project.id.clone(); let project_id = props.project.id.clone();
let force_update_handle = props.forceupdate.clone(); let force_update_handle = props.forceupdate.clone();
let index = props.index;
Callback::from(move |event: MouseEvent| { Callback::from(move |event: MouseEvent| {
if *is_attempting_delete { if *is_attempting_delete {
let project_id = project_id.clone(); let project_id = project_id.clone();
let force_update_handle = force_update_handle.clone(); let force_update_handle = force_update_handle.clone();
let index = index.clone();
wasm_bindgen_futures::spawn_local(async move { wasm_bindgen_futures::spawn_local(async move {
match delete_project(&project_id).await { 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}")} Err(error) => {log::error!("Error deleting project: {error}")}
}; };
}); });
@ -77,5 +79,5 @@ pub fn admin_project(props: &AdminProjectProps) -> Html {
pub struct AdminProjectProps { pub struct AdminProjectProps {
pub project: ProjectCardDto, pub project: ProjectCardDto,
pub index: usize, pub index: usize,
pub forceupdate: Callback<()>, pub forceupdate: Callback<usize>,
} }

View File

@ -262,8 +262,6 @@ pub fn generate_fields_for_project(props: &ProjectFieldsProps) -> Html {
Callback::from(move |_: MouseEvent| { Callback::from(move |_: MouseEvent| {
let navigator = navigator.clone(); let navigator = navigator.clone();
let edit_type = edit_type.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_city_handle = location_city.clone();
let location_district_handle = location_district.clone(); let location_district_handle = location_district.clone();
let agent_handle = agent.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() { let agent_id = match (*agent_handle).clone() {
Some(selected_agent) => selected_agent.id, Some(selected_agent) => selected_agent.id,
None => { None => {

View File

@ -11,7 +11,6 @@ use crate::{
#[function_component(AdminProjects)] #[function_component(AdminProjects)]
pub fn admin_projects() -> Html { pub fn admin_projects() -> Html {
let projects = use_state(|| Vec::new()); let projects = use_state(|| Vec::new());
let force_update_handle = use_force_update();
use_state(|| { use_state(|| {
let projects_handle = projects.clone(); let projects_handle = projects.clone();
wasm_bindgen_futures::spawn_local(async move { 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! { {(*projects).clone().into_iter().enumerate().map(|(key, project)| html! {
<> <>
<AdminProject project={project} index={key} forceupdate={ <AdminProject project={project} index={key} forceupdate={
let force_update_handle = force_update_handle.clone(); let projects_handle = projects.clone();
Callback::from(move |_| { Callback::from(move |index| {
force_update_handle.force_update() let mut projects = (*projects_handle).clone();
projects.remove(index);
projects_handle.set(projects);
})}/> })}/>
<div class={"admin-navbar-divider"}></div> <div class={"admin-navbar-divider"}></div>
</> </>