summary refs log tree commit diff stats
path: root/src/pages
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-09-26 17:43:43 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-09-26 17:43:43 +0200
commit32847efa04029d81f9d8cf7a37999cb3cbb1e145 (patch)
tree8a0a7bc135643a6fbf45bf48141d9dfcb2085183 /src/pages
downloadweb-client-32847efa04029d81f9d8cf7a37999cb3cbb1e145.zip
chore: Initial Commit
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/home.rs95
-rw-r--r--src/pages/mod.rs2
-rw-r--r--src/pages/not_found.rs6
3 files changed, 103 insertions, 0 deletions
diff --git a/src/pages/home.rs b/src/pages/home.rs
new file mode 100644
index 0000000..9c86833
--- /dev/null
+++ b/src/pages/home.rs
@@ -0,0 +1,95 @@
+use std::sync::Arc;
+
+use leptos::{
+    IntoView, component,
+    error::ErrorBoundary,
+    prelude::{
+        ClassAttribute, CollectView, ElementChild, Get, Read, ReadSignal, Set, With, signal,
+    },
+    reactive::spawn_local,
+    server::{LocalResource, Resource},
+    view,
+};
+use rocie_client::apis::{
+    api_get_product_api::{ProductsError, products},
+    configuration::Configuration,
+};
+
+#[component]
+pub fn Home(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! {
+        <ErrorBoundary fallback=|errors| {
+            view! {
+                <h1>"Uh oh! Something went wrong!"</h1>
+
+                <p>"Errors: "</p>
+                // Render a list of errors as strings - good for development purposes
+                <ul>
+                    {move || {
+                        errors
+                            .get()
+                            .into_iter()
+                            .map(|(_, e)| view! { <li>{e.to_string()}</li> })
+                            .collect_view()
+                    }}
+                </ul>
+            }
+        }>
+
+            <nav>
+                <div class="nav">
+                    <img
+                        src="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_RGB.svg"
+                        alt="Rocie Logo"
+                        height="200"
+                        width="400"
+                    />
+                    <h1>Rocie</h1>
+                </div>
+            </nav>
+
+            <div class="container">
+                <div class="container">
+                    <h1>"Inventory"</h1>
+
+                    <p>{read_status}</p>
+                </div>
+
+                <div class="container">
+                    <h1>"Recipies"</h1>
+                </div>
+
+                <div class="container">
+                    <h1>"Shopping list"</h1>
+                </div>
+            </div>
+        </ErrorBoundary>
+    }
+}
diff --git a/src/pages/mod.rs b/src/pages/mod.rs
new file mode 100644
index 0000000..8829694
--- /dev/null
+++ b/src/pages/mod.rs
@@ -0,0 +1,2 @@
+pub mod home;
+pub mod not_found;
diff --git a/src/pages/not_found.rs b/src/pages/not_found.rs
new file mode 100644
index 0000000..7b5c127
--- /dev/null
+++ b/src/pages/not_found.rs
@@ -0,0 +1,6 @@
+use leptos::{IntoView, component, prelude::ElementChild, view};
+
+#[component]
+pub fn NotFound() -> impl IntoView {
+    view! { <h1>"Uh oh!" <br /> "We couldn't find that page!"</h1> }
+}