diff --git a/src/pages/admin/edit.rs b/src/pages/admin/edit.rs index 31ef606..087a320 100644 --- a/src/pages/admin/edit.rs +++ b/src/pages/admin/edit.rs @@ -6,7 +6,7 @@ use yew_router::prelude::use_navigator; use crate::{ api::backend::{ - get_project_listing, get_agent_with_id, + get_project_listing, get_agent_with_id, get_unit_with_id, }, components::{ admin_nav_bar::AdminNavigationBar, @@ -23,6 +23,8 @@ pub fn edit_page(props: &AdminEditPageProps) -> Html { let unit = use_state(|| None); use_state(|| { let listing = listing.clone(); + let agent = agent.clone(); + let unit = unit.clone(); match props.edit_item { EditItem::Agent => { match props.edit_type { @@ -56,7 +58,22 @@ pub fn edit_page(props: &AdminEditPageProps) -> Html { } }; } - EditItem::Unit(_) => {} + EditItem::Unit(_) => { + match props.edit_type { + EditType::New => {} + EditType::Existing(uid) => { + wasm_bindgen_futures::spawn_local(async move { + let unit_result = get_unit_with_id(&uid).await; + match unit_result { + Ok(unit_persisted) => { + unit.set(Some(unit_persisted)); + } + Err(error) => log::error!("Error loading unit: {error}"), + }; + }); + } + }; + } } }); @@ -78,9 +95,9 @@ pub fn edit_page(props: &AdminEditPageProps) -> Html {