summary refs log tree commit diff stats
path: root/src/pages/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/mod.rs')
-rw-r--r--src/pages/mod.rs83
1 files changed, 81 insertions, 2 deletions
diff --git a/src/pages/mod.rs b/src/pages/mod.rs
index b8a68c7..8a38db2 100644
--- a/src/pages/mod.rs
+++ b/src/pages/mod.rs
@@ -1,7 +1,86 @@
+pub mod associate_barcode;
 pub mod buy;
+pub mod create_product;
+pub mod create_product_parent;
+pub mod create_recipe;
 pub mod home;
 pub mod inventory;
+pub mod login;
 pub mod not_found;
+pub mod product;
+pub mod products;
+pub mod provision;
+pub mod recipe;
 pub mod recipies;
-pub mod create_product;
-pub mod associate_barcode;
+pub mod units;
+
+macro_rules! mk_render_parents {
+    (
+        self = $self:ident,
+        parent_type = $parent_type:ty,
+        item_type = $item_type:ty,
+        value_renderer = $value_renderer:ident,
+        under_parent_fetcher = $under_parent_fetcher:ident,
+        indirect_fetcher = $indirect_fetcher:ident,
+        direct_fetcher = $direct_fetcher:ident $(,)?
+    ) => {
+        fn $self(
+            parents: Option<Vec<$parent_type>>,
+            toplevel_items: Option<Vec<$item_type>>,
+        ) -> impl IntoView {
+            use leptos::prelude::IntoAny;
+
+            view! {
+                {
+                    parents.map(|parents| {
+                        parents
+                            .into_iter()
+                            .map(|parent| {
+                                view! {
+                                    <li>
+                                        <details>
+                                            <summary>{parent.name} {" ("} {
+                                                    AsyncFetch! {
+                                                        @map_error_in_producer
+                                                        fetcher = $indirect_fetcher(parent.id),
+                                                        producer = |products| {products.len()}
+                                                    }
+                                            } {")"}</summary>
+
+                                            <ul class="flex flex-col p-2">
+                                                {
+                                                    AsyncFetch! {
+                                                        @map_error_in_producer
+                                                        fetcher = $under_parent_fetcher(parent.id),
+                                                        producer = |val| $self(val, None)
+                                                    }
+                                                }
+
+                                                {
+                                                    AsyncFetch! {
+                                                        @map_error_in_producer
+                                                        fetcher = $direct_fetcher(parent.id),
+                                                        producer = $value_renderer
+                                                    }
+                                                }
+                                            </ul>
+                                        </details>
+                                    </li>
+                                }
+                                .into_any()
+                            })
+                            .collect::<Vec<_>>()
+                    })
+                }
+                {
+                    if let Some(toplevel_items) = toplevel_items {
+                        $value_renderer(toplevel_items).into_any()
+                    } else {
+                        ().into_any()
+                    }
+                }
+            }
+        }
+    };
+}
+use mk_render_parents;