doordesk-rs/app/src/components/ui/articles.rs
2024-01-29 18:01:33 -05:00

46 lines
1.2 KiB
Rust

use crate::components::slingshot::*;
use crate::components::ui::containers::*;
use leptos::*;
use serde::*;
#[derive(Clone, Serialize, Deserialize)]
pub struct ArticleInterface {
pub content_type: String,
pub title: String,
pub date: String, // make datetime?
pub content: String,
}
#[component]
pub fn Article(data: ArticleInterface) -> impl IntoView {
view! {
<Container>
<article>
<h1 class="text-3xl font-light text-orange-600 capitalize max-6-xs">
{&data.title}
</h1>
<hr class="opacity-50"/>
<span class="pt-0 pb-3.5 text-xs opacity-50 m-t">{&data.date}</span>
<div inner_html=&data.content></div>
</article>
</Container>
}
}
#[component]
pub fn ArticleBuilder() -> impl IntoView {
let data_resource = create_local_resource(
|| (),
|_| async move { slingshot("./public/blog".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
}