From 71ec8e2234dbdd915e7f92e48d6b4847bd8c24b8 Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 25 Apr 2023 08:58:44 -0400 Subject: [PATCH] Loaded edit pages for each --- src/pages/admin/edit.rs | 25 +++++++++++++++++++++---- src/pages/admin/fields/unit.rs | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) 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 {
{ match props.edit_item { - EditItem::Agent => { html! { } }, + EditItem::Agent => { html! { } }, EditItem::Project => { html! { } }, - EditItem::Unit(project_id) => { html! { } }, + EditItem::Unit(project_id) => { html! { } }, } }
diff --git a/src/pages/admin/fields/unit.rs b/src/pages/admin/fields/unit.rs index e93e482..f4245a8 100644 --- a/src/pages/admin/fields/unit.rs +++ b/src/pages/admin/fields/unit.rs @@ -1,4 +1,5 @@ use jl_types::domain::unit::Unit; +use uuid::Uuid; use yew::prelude::*; use yew_router::prelude::use_navigator;