summary refs log tree commit diff stats
path: root/src/components/product_overview.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-09-26 20:15:48 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-09-26 20:15:48 +0200
commitfd832ce7a3660bd81b5476477ecdc2bc822df5c2 (patch)
tree245ebcd20b3def57f46e7d28b3f4e551644a1afc /src/components/product_overview.rs
parentchore: Initial Commit (diff)
downloadweb-client-fd832ce7a3660bd81b5476477ecdc2bc822df5c2.zip
chore: Second version
Diffstat (limited to '')
-rw-r--r--src/components/product_overview.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/components/product_overview.rs b/src/components/product_overview.rs
new file mode 100644
index 0000000..4e95335
--- /dev/null
+++ b/src/components/product_overview.rs
@@ -0,0 +1,47 @@
+use std::sync::Arc;
+
+use leptos::{
+    IntoView, component,
+    prelude::{ElementChild, Set, signal},
+    task::spawn_local,
+    view,
+};
+use rocie_client::apis::{api_get_product_api::products, configuration::Configuration};
+
+use crate::components::container::Container;
+
+#[component]
+pub fn ProductOverview(config: Arc<Configuration>) -> impl IntoView {
+    let (read_status, write_status) = signal("Loading..".to_owned());
+
+    {
+        let local_config = Arc::clone(&config);
+
+        spawn_local(async move {
+            let products = products(&local_config).await;
+
+            write_status.set(
+                products
+                    .as_ref()
+                    .map(move |products| {
+                        let products_num = products.len();
+                        let plural_s = if products_num == 1 { "" } else { "s" };
+                        let products_value = 2;
+                        let products_currency = "EUR";
+                        format!(
+                            "You have {products_num} product{plural_s} \
+                         in stock with a value \
+                         of {products_value} {products_currency}.",
+                        )
+                    })
+                    .unwrap(),
+            );
+        });
+    }
+
+    view! {
+        <Container header="Inventory">
+            <p>{read_status}</p>
+        </Container>
+    }
+}