pull out article builder
This commit is contained in:
parent
44f1d3acef
commit
f4695b7729
2 changed files with 22 additions and 13 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::components::slingshot::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -9,6 +10,24 @@ pub struct ArticleData {
|
||||||
pub content: String,
|
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]
|
#[component]
|
||||||
pub fn Article(data: ArticleData) -> impl IntoView {
|
pub fn Article(data: ArticleData) -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
|
|
|
@ -5,18 +5,6 @@ use leptos::*;
|
||||||
|
|
||||||
#[island]
|
#[island]
|
||||||
pub fn Home() -> impl IntoView {
|
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! {
|
view! {
|
||||||
<Suspense fallback=move || {
|
<Suspense fallback=move || {
|
||||||
|
@ -24,7 +12,9 @@ pub fn Home() -> impl IntoView {
|
||||||
}>
|
}>
|
||||||
<ErrorBoundary fallback=|errors| {
|
<ErrorBoundary fallback=|errors| {
|
||||||
view! { <ErrorTemplate errors=errors/> }
|
view! { <ErrorTemplate errors=errors/> }
|
||||||
}>{articles_view}</ErrorBoundary>
|
}>
|
||||||
|
<ArticleBuilder/>
|
||||||
|
</ErrorBoundary>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue