From 0e5cd9363274f4e23c990a95fec3485b7ea724db Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:10:19 -0500 Subject: [PATCH] use a vec --- doordesk/app/src/components/slingshot.rs | 26 ++++++++++++++++-------- doordesk/app/src/routes/home.rs | 16 ++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/doordesk/app/src/components/slingshot.rs b/doordesk/app/src/components/slingshot.rs index 64054f7..53453d6 100644 --- a/doordesk/app/src/components/slingshot.rs +++ b/doordesk/app/src/components/slingshot.rs @@ -1,8 +1,8 @@ use leptos::*; use serde::{Deserialize, Serialize}; -use std::time::Duration; use std::thread::sleep; +use std::time::Duration; pub fn fetch(path: &str) -> String { format!("https://dennis.doordesk.net/{path}") @@ -17,14 +17,22 @@ pub struct ArticleData { } #[server(Slingshot)] -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"), - }; +pub async fn slingshot() -> Result, ServerFnError> { + let data_vec = vec![ + ArticleData { + content_type: String::from("Blog"), + title: String::from("Test article"), + date: String::from("12/21/2022"), + content: String::from("Testicles"), + }, + ArticleData { + content_type: String::from("Blog"), + title: String::from("Test article 2"), + date: String::from("12/22/2022"), + content: String::from("Testicless"), + }, + ]; sleep(Duration::from_secs(1)); - Ok(data) + Ok(data_vec) } diff --git a/doordesk/app/src/routes/home.rs b/doordesk/app/src/routes/home.rs index 943ee49..3a7e347 100644 --- a/doordesk/app/src/routes/home.rs +++ b/doordesk/app/src/routes/home.rs @@ -6,15 +6,17 @@ use leptos::*; pub fn Home() -> impl IntoView { let data_resource = create_local_resource(|| (), |_| async move { slingshot().await }); + let articles_view = move || { + data_resource.and_then(|data| { + data.iter() + .map(|article| view! {
}) + .collect_view() + }) + }; + view! { "Loading..."

} - }> - {move || match data_resource.get() { - None => view! {

"Loading..."

}.into_view(), - Some(data) => view! {
}.into_view(), - }} - - + }>{articles_view} } }