use leptos::*; use crate::{prelude::*, URL_SENSITIVE}; use apb::{target::Addressed, Base, Collection, Object}; #[component] pub fn Attachment( object: serde_json::Value, #[prop(optional)] sensitive: bool ) -> impl IntoView { let (expand, set_expand) = create_signal(false); let href = object.url().id().unwrap_or_default(); let media_type = object.media_type() .unwrap_or("image/png") // TODO weird defaulting to png????? .to_string(); let kind = media_type .split('/') .next() .unwrap_or("image") .to_string(); match kind.as_str() { "image" => view! {

}.into_view(), "video" => view! {
}.into_view(), "audio" => view! {

}.into_view(), _ => view! {

{media_type}

{object.name().unwrap_or_default().to_string()}

}.into_view(), } } #[component] pub fn Object(object: serde_json::Value) -> impl IntoView { let uid = object.id().unwrap_or_default().to_string(); let content = dissolve::strip_html_tags(object.content().unwrap_or_default()); let author_id = object.attributed_to().id().unwrap_or_default(); let author = CACHE.get_or(&author_id, serde_json::Value::String(author_id.clone())); let sensitive = object.sensitive().unwrap_or_default(); let attachments = object.attachment() .map(|x| view! { }) .collect_view(); let comments = object.replies().get() .map(|x| x.total_items().unwrap_or(0)) .filter(|x| *x > 0) .map(|x| view! { {x} }); let likes = object.audience().get() .map(|x| x.total_items().unwrap_or(0)) .filter(|x| *x > 0) .map(|x| view! { {x} }); let shares = object.generator().get() .map(|x| x.total_items().unwrap_or(0)) .filter(|x| *x > 0) .map(|x| view! { {x} }); let attachments_padding = if object.attachment().is_empty() { None } else { Some(view! {
}) }; view! {
{object.in_reply_to().id().map(|reply| view! { reply })} "↗"
{content.into_iter().map(|x| view! {

{x}

}).collect_view()} {attachments_padding} {attachments}
{comments}" 📨" {likes}" ⭐" {shares}" 🚀"
} } #[component] pub fn Summary(summary: Option, open: bool, children: Children) -> impl IntoView { match summary.filter(|x| !x.is_empty()) { None => children().into_view(), Some(summary) => view! {
{summary} {children()}
}.into_view(), } }