use leptos::{ IntoView, component, prelude::{ClassAttribute, ElementChild}, view, }; use rocie_client::models::{Product, ProductAmount, ProductId, Unit}; use crate::{ api::{ amount_by_id_wrapped, product_by_id_wrapped, products_in_storage_wrapped, unit_by_id_wrapped, }, components::{async_fetch::AsyncFetch, site_header::SiteHeader}, }; #[component] pub fn Inventory() -> impl IntoView { view! { } } fn render_products(products: Vec) -> impl IntoView { products .into_iter() .map(|product| { AsyncFetch! { @map_error_in_producer fetcher = get_full_product_by_id(product.id), producer = format_full_product, } }) .collect::>() } 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! {
  • {product.name}
  • {format!("{} {}", amount.amount.value, unit.short_name)}
} }