use a vec
This commit is contained in:
parent
6c8bc1ae27
commit
0e5cd93632
2 changed files with 26 additions and 16 deletions
|
@ -1,8 +1,8 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn fetch(path: &str) -> String {
|
pub fn fetch(path: &str) -> String {
|
||||||
format!("https://dennis.doordesk.net/{path}")
|
format!("https://dennis.doordesk.net/{path}")
|
||||||
|
@ -17,14 +17,22 @@ pub struct ArticleData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(Slingshot)]
|
#[server(Slingshot)]
|
||||||
pub async fn slingshot() -> Result<ArticleData, ServerFnError> {
|
pub async fn slingshot() -> Result<Vec<ArticleData>, ServerFnError> {
|
||||||
let data = ArticleData {
|
let data_vec = vec![
|
||||||
content_type: String::from("Blog"),
|
ArticleData {
|
||||||
title: String::from("Test article"),
|
content_type: String::from("Blog"),
|
||||||
date: String::from("12/21/2022"),
|
title: String::from("Test article"),
|
||||||
content: String::from("Testicles"),
|
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));
|
sleep(Duration::from_secs(1));
|
||||||
Ok(data)
|
Ok(data_vec)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,17 @@ use leptos::*;
|
||||||
pub fn Home() -> impl IntoView {
|
pub fn Home() -> impl IntoView {
|
||||||
let data_resource = create_local_resource(|| (), |_| async move { slingshot().await });
|
let data_resource = create_local_resource(|| (), |_| async move { slingshot().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 || {
|
||||||
view! { <p>"Loading..."</p> }
|
view! { <p>"Loading..."</p> }
|
||||||
}>
|
}>{articles_view}</Suspense>
|
||||||
{move || match data_resource.get() {
|
|
||||||
None => view! { <p>"Loading..."</p> }.into_view(),
|
|
||||||
Some(data) => view! { <Article data=data.unwrap()/> }.into_view(),
|
|
||||||
}}
|
|
||||||
|
|
||||||
</Suspense>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue