use leptos::{
IntoView, component,
prelude::{ClassAttribute, ElementChild},
view,
};
use rocie_client::models::{Product, ProductAmount, ProductId, Unit};
use crate::{
api::{
amount_by_id_404_wrapped, product_by_id_wrapped, products_in_storage_wrapped,
unit_by_id_wrapped,
},
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,
}
}
}
}
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