From f4695b77295733834ed727004b337b740daa5bdd Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:18:36 -0500 Subject: [PATCH] pull out article builder --- app/src/components/article.rs | 19 +++++++++++++++++++ app/src/routes/home.rs | 16 +++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/src/components/article.rs b/app/src/components/article.rs index 0382f9f..31e3a5e 100644 --- a/app/src/components/article.rs +++ b/app/src/components/article.rs @@ -1,3 +1,4 @@ +use crate::components::slingshot::*; use leptos::*; use serde::{Deserialize, Serialize}; @@ -9,6 +10,24 @@ pub struct ArticleData { pub content: String, } +#[component] +pub fn ArticleBuilder() -> impl IntoView { + let data_resource = create_local_resource( + || (), + |_| async move { slingshot("./public/articles".to_string()).await }, + ); + + let articles_view = move || { + data_resource.and_then(|data| { + data.iter() + .map(|article| view! {
}) + .collect_view() + }) + }; + + articles_view +} + #[component] pub fn Article(data: ArticleData) -> impl IntoView { view! { diff --git a/app/src/routes/home.rs b/app/src/routes/home.rs index 35ed087..95cf032 100644 --- a/app/src/routes/home.rs +++ b/app/src/routes/home.rs @@ -5,18 +5,6 @@ use leptos::*; #[island] pub fn Home() -> impl IntoView { - let data_resource = create_local_resource( - || (), - |_| async move { slingshot("./public/articles".to_string()).await }, - ); - - let articles_view = move || { - data_resource.and_then(|data| { - data.iter() - .map(|article| view! {
}) - .collect_view() - }) - }; view! { impl IntoView { }> } - }>{articles_view} + }> + + } }