From f6a3fb9c4d8dd86f78c9f75a23c1ac35bf35d4eb Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 19 Mar 2026 07:45:14 +0100 Subject: feat(treewide): Commit MVP --- src/pages/inventory.rs | 68 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'src/pages/inventory.rs') diff --git a/src/pages/inventory.rs b/src/pages/inventory.rs index b2ce4a1..0ad5613 100644 --- a/src/pages/inventory.rs +++ b/src/pages/inventory.rs @@ -7,26 +7,33 @@ use rocie_client::models::{Product, ProductAmount, ProductId, Unit}; use crate::{ api::{ - amount_by_id_wrapped, product_by_id_wrapped, products_in_storage_wrapped, + amount_by_id_404_wrapped, product_by_id_wrapped, products_in_storage_wrapped, unit_by_id_wrapped, }, - components::{async_fetch::AsyncFetch, site_header::SiteHeader}, + components::{ + async_fetch::AsyncFetch, catch_errors::CatchErrors, login_wall::LoginWall, + site_header::SiteHeader, + }, }; #[component] pub fn Inventory() -> impl IntoView { view! { - + + + -
    - { - AsyncFetch! { - @map_error_in_producer - fetcher = products_in_storage_wrapped(), - producer = render_products, - } - } -
+
    + { + AsyncFetch! { + @map_error_in_producer + fetcher = products_in_storage_wrapped(), + producer = render_products, + } + } +
+
+
} } @@ -45,23 +52,30 @@ fn render_products(products: Vec) -> impl IntoView { async fn get_full_product_by_id( id: ProductId, -) -> Result<(Product, ProductAmount, Unit), leptos::error::Error> { +) -> Result, 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?; + let amount = amount_by_id_404_wrapped(id).await?; - Ok((product, amount, unit)) -} + if let Some(amount) = amount { + let unit = unit_by_id_wrapped(amount.amount.unit).await?; -fn format_full_product((product, amount, unit): (Product, ProductAmount, Unit)) -> impl IntoView { - view! { -
    -
  • {product.name}
  • -
  • - - {format!("{} {}", amount.amount.value, unit.short_name)} - -
  • -
+ Ok(Some((product, amount, unit))) + } else { + Ok(None) } } + +fn format_full_product(maybe_product: Option<(Product, ProductAmount, Unit)>) -> impl IntoView { + maybe_product.map(|(product, amount, unit)| { + view! { +
    +
  • {product.name}
  • +
  • + + {format!("{} {}", amount.amount.value, unit.short_name)} + +
  • +
+ } + }) +} -- cgit 1.4.1