pull out article builder

This commit is contained in:
Adam 2024-01-26 22:18:36 -05:00
parent 44f1d3acef
commit f4695b7729
2 changed files with 22 additions and 13 deletions

View file

@ -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! { <Article data=article.clone()/> })
.collect_view()
})
};
articles_view
}
#[component]
pub fn Article(data: ArticleData) -> impl IntoView {
view! {

View file

@ -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! { <Article data=article.clone()/> })
.collect_view()
})
};
view! {
<Suspense fallback=move || {
@ -24,7 +12,9 @@ pub fn Home() -> impl IntoView {
}>
<ErrorBoundary fallback=|errors| {
view! { <ErrorTemplate errors=errors/> }
}>{articles_view}</ErrorBoundary>
}>
<ArticleBuilder/>
</ErrorBoundary>
</Suspense>
}
}