From 32847efa04029d81f9d8cf7a37999cb3cbb1e145 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 26 Sep 2025 17:43:43 +0200 Subject: chore: Initial Commit --- src/pages/home.rs | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/pages/mod.rs | 2 ++ src/pages/not_found.rs | 6 ++++ 3 files changed, 103 insertions(+) create mode 100644 src/pages/home.rs create mode 100644 src/pages/mod.rs create mode 100644 src/pages/not_found.rs (limited to 'src/pages') 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) -> 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! { + "Uh oh! Something went wrong!" + +

"Errors: "

+ // Render a list of errors as strings - good for development purposes +
    + {move || { + errors + .get() + .into_iter() + .map(|(_, e)| view! {
  • {e.to_string()}
  • }) + .collect_view() + }} +
+ } + }> + + + +
+
+

"Inventory"

+ +

{read_status}

+
+ +
+

"Recipies"

+
+ +
+

"Shopping list"

+
+
+
+ } +} 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! {

"Uh oh!"
"We couldn't find that page!"

} +} -- cgit 1.4.1