From b9c37e16785eedfcf6f71bd51e5819403e03e2cc Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Sat, 6 Jan 2024 04:26:09 -0500 Subject: [PATCH] pain --- doordesk/Cargo.lock | 9 ++--- doordesk/app/Cargo.toml | 1 + doordesk/app/src/components.rs | 1 + doordesk/app/src/components/article.rs | 45 ++++++++++++++++++------ doordesk/app/src/components/slingshot.rs | 22 ++++++++++++ doordesk/app/src/lib.rs | 14 ++++---- doordesk/app/src/routes/blog.rs | 5 +-- doordesk/app/src/routes/home.rs | 5 +-- doordesk/app/src/routes/projects.rs | 5 +-- 9 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 doordesk/app/src/components/slingshot.rs diff --git a/doordesk/Cargo.lock b/doordesk/Cargo.lock index 5eef7bb..b2b08ac 100644 --- a/doordesk/Cargo.lock +++ b/doordesk/Cargo.lock @@ -86,6 +86,7 @@ dependencies = [ "leptos_axum", "leptos_meta", "leptos_router", + "serde", "thiserror", ] @@ -1877,9 +1878,9 @@ checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba" [[package]] name = "serde" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] @@ -1897,9 +1898,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", diff --git a/doordesk/app/Cargo.toml b/doordesk/app/Cargo.toml index 88f64c6..ad03c30 100644 --- a/doordesk/app/Cargo.toml +++ b/doordesk/app/Cargo.toml @@ -14,6 +14,7 @@ leptos_axum = { workspace = true, optional = true } http.workspace = true cfg-if.workspace = true thiserror.workspace = true +serde = "1.0.195" [features] default = [] diff --git a/doordesk/app/src/components.rs b/doordesk/app/src/components.rs index 0c5307e..39d2056 100644 --- a/doordesk/app/src/components.rs +++ b/doordesk/app/src/components.rs @@ -1 +1,2 @@ pub mod article; +pub mod slingshot; diff --git a/doordesk/app/src/components/article.rs b/doordesk/app/src/components/article.rs index 3aaf552..91be72a 100644 --- a/doordesk/app/src/components/article.rs +++ b/doordesk/app/src/components/article.rs @@ -1,19 +1,42 @@ +use crate::components::slingshot::*; use leptos::*; #[component] pub fn Article() -> impl IntoView { - // Creates a reactive value to update the button - let (count, set_count) = create_signal(0); - let on_click = move |_| set_count.update(|count| *count += 1); + let data = create_resource( + || (), + |_| async move { + logging::log!("loading data from slingshot"); + slingshot().await + }, + ); view! { -
-

"ayo"

-
- "today" -
- -
-
+ +
+

+ {move || match data.get() { + None => "Loading...".to_string(), + Some(data) => data.unwrap().title, + }} + +

+
+ + {move || match data.get() { + None => "Loading...".to_string(), + Some(data) => data.unwrap().date, + }} + + +
+ {move || match data.get() { + None => "Loading...".to_string(), + Some(data) => data.unwrap().content, + }} + +
+
+
} } diff --git a/doordesk/app/src/components/slingshot.rs b/doordesk/app/src/components/slingshot.rs new file mode 100644 index 0000000..1903139 --- /dev/null +++ b/doordesk/app/src/components/slingshot.rs @@ -0,0 +1,22 @@ +use leptos::*; +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ArticleData { + pub content_type: String, + pub title: String, + pub date: String, // make datetime? + pub content: String, +} + +#[server(Slingshot, "/api", "Cbor")] +pub async fn slingshot() -> Result { + let data = ArticleData { + content_type: String::from("Blog"), + title: String::from("Test article"), + date: String::from("12/21/2022"), + content: String::from("Testicles"), + }; + + Ok(data) +} diff --git a/doordesk/app/src/lib.rs b/doordesk/app/src/lib.rs index d55692d..8852da9 100644 --- a/doordesk/app/src/lib.rs +++ b/doordesk/app/src/lib.rs @@ -30,11 +30,11 @@ pub fn App() -> impl IntoView { }>