// rocie - An enterprise grocery management system - Web app // // Copyright (C) 2026 Benedikt Peetz // SPDX-License-Identifier: GPL-3.0-or-later // // This file is part of Rocie. // // You should have received a copy of the License along with this program. // If not, see . use leptos::{ IntoView, component, prelude::{ClassAttribute, CollectView, ElementChild}, view, }; use rocie_client::models::{Unit, UnitPropertyId}; use crate::{ api::{unit_properties_wrapped, units_by_property_id_wrapped}, components::{ async_fetch::{AsyncFetch, AsyncResource}, catch_errors::CatchErrors, login_wall::LoginWall, site_header::SiteHeader, }, }; #[component] pub(crate) fn Units() -> impl IntoView { view! {
    { AsyncFetch! { @map_error_in_producer fetcher = unit_properties_wrapped(), producer = |unit_properties| { unit_properties.into_iter().map(|unit_property| { let resource = AsyncResource!{ ( unit_property_name: String = unit_property.name.clone(), unit_property_id: UnitPropertyId = unit_property.id ) -> Result<(Vec, String), leptos::error::Error> { Ok( ( units_by_property_id_wrapped(unit_property_id).await?, unit_property_name ) ) } }; AsyncFetch! { @map_error_in_producer from_resource = resource, producer = |(units, unit_property_name)| { let units = units.into_iter().map(|unit| view!{
  • {format!("{} ({})", unit.full_name_singular, unit.short_name)}
  • }).collect::>(); view! {
  • {unit_property_name}

      {units}
  • } } } }).collect_view() }, } }
} }