use leptos::{
IntoView, component,
prelude::{ClassAttribute, ElementChild},
view,
};
use rocie_client::models::{Product, ProductAmount, Unit};
use crate::{
api::{get_full_product_by_id, get_products},
components::{async_fetch::AsyncFetch, site_header::SiteHeader},
};
#[component]
pub fn Inventory() -> impl IntoView {
view! {
{
AsyncFetch! {
@map_error_in_producer
fetcher = get_products(),
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::>()
}
fn format_full_product((product, amount, unit): (Product, ProductAmount, Unit)) -> impl IntoView {
view! {
- {product.name}
-
{format!("{} {}", amount.amount.value, unit.short_name)}
}
}