diff options
Diffstat (limited to 'src/pages/inventory.rs')
| -rw-r--r-- | src/pages/inventory.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/pages/inventory.rs b/src/pages/inventory.rs index e5ff6ae..b2ce4a1 100644 --- a/src/pages/inventory.rs +++ b/src/pages/inventory.rs @@ -3,10 +3,13 @@ use leptos::{ prelude::{ClassAttribute, ElementChild}, view, }; -use rocie_client::models::{Product, ProductAmount, Unit}; +use rocie_client::models::{Product, ProductAmount, ProductId, Unit}; use crate::{ - api::{get_full_product_by_id, get_products}, + api::{ + amount_by_id_wrapped, product_by_id_wrapped, products_in_storage_wrapped, + unit_by_id_wrapped, + }, components::{async_fetch::AsyncFetch, site_header::SiteHeader}, }; @@ -19,7 +22,7 @@ pub fn Inventory() -> impl IntoView { { AsyncFetch! { @map_error_in_producer - fetcher = get_products(), + fetcher = products_in_storage_wrapped(), producer = render_products, } } @@ -40,6 +43,16 @@ fn render_products(products: Vec<Product>) -> impl IntoView { .collect::<Vec<_>>() } +async fn get_full_product_by_id( + id: ProductId, +) -> Result<(Product, ProductAmount, Unit), leptos::error::Error> { + let product = product_by_id_wrapped(id).await?; + let amount = amount_by_id_wrapped(id).await?; + let unit = unit_by_id_wrapped(amount.amount.unit).await?; + + Ok((product, amount, unit)) +} + fn format_full_product((product, amount, unit): (Product, ProductAmount, Unit)) -> impl IntoView { view! { <ul class="my-3"> |
