From f6a3fb9c4d8dd86f78c9f75a23c1ac35bf35d4eb Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 19 Mar 2026 07:45:14 +0100 Subject: feat(treewide): Commit MVP --- src/pages/units.rs | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/pages/units.rs (limited to 'src/pages/units.rs') diff --git a/src/pages/units.rs b/src/pages/units.rs new file mode 100644 index 0000000..a5d8655 --- /dev/null +++ b/src/pages/units.rs @@ -0,0 +1,78 @@ +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() + }, + } + } +
+
+
+ } +} -- cgit 1.4.1