diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-03-19 07:45:14 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-03-19 07:45:14 +0100 |
| commit | f6a3fb9c4d8dd86f78c9f75a23c1ac35bf35d4eb (patch) | |
| tree | 5f28fbca03d83921b568f7cb1708374456d9ec42 /src/pages/inventory.rs | |
| parent | feat(treewide): Add further buttons (diff) | |
| download | web-client-f6a3fb9c4d8dd86f78c9f75a23c1ac35bf35d4eb.zip | |
feat(treewide): Commit MVP
Diffstat (limited to 'src/pages/inventory.rs')
| -rw-r--r-- | src/pages/inventory.rs | 68 |
1 files changed, 41 insertions, 27 deletions
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! { - <SiteHeader logo=icondata_io::IoArrowBack back_location="/" name="Inventory" /> + <CatchErrors> + <LoginWall back=move || "/inventory".to_owned()> + <SiteHeader logo=icondata_io::IoArrowBack back_location="/" name="Inventory" /> - <ul class="flex flex-col p-2 m-2"> - { - AsyncFetch! { - @map_error_in_producer - fetcher = products_in_storage_wrapped(), - producer = render_products, - } - } - </ul> + <ul class="flex flex-col p-2 m-2"> + { + AsyncFetch! { + @map_error_in_producer + fetcher = products_in_storage_wrapped(), + producer = render_products, + } + } + </ul> + </LoginWall> + </CatchErrors> } } @@ -45,23 +52,30 @@ fn render_products(products: Vec<Product>) -> impl IntoView { async fn get_full_product_by_id( id: ProductId, -) -> Result<(Product, ProductAmount, Unit), leptos::error::Error> { +) -> Result<Option<(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?; + 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! { - <ul class="my-3"> - <li class="m-2">{product.name}</li> - <li class="m-2"> - <span class="bg-gray-200 p-1 px-2 rounded-lg"> - {format!("{} {}", amount.amount.value, unit.short_name)} - </span> - </li> - </ul> + 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! { + <ul class="my-3"> + <li class="m-2">{product.name}</li> + <li class="m-2"> + <span class="bg-gray-200 p-1 px-2 rounded-lg"> + {format!("{} {}", amount.amount.value, unit.short_name)} + </span> + </li> + </ul> + } + }) +} |
