2024-04-21 17:43:36 +02:00
|
|
|
use leptos::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2024-04-21 18:56:25 +02:00
|
|
|
use apb::{target::Addressed, Base, Object};
|
2024-04-21 17:43:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn Object(object: serde_json::Value) -> impl IntoView {
|
2024-04-22 01:01:20 +02:00
|
|
|
let uid = object.id().unwrap_or_default().to_string();
|
2024-04-21 17:43:36 +02:00
|
|
|
let content = dissolve::strip_html_tags(object.content().unwrap_or_default());
|
2024-04-21 18:56:25 +02:00
|
|
|
let author_id = object.attributed_to().id().unwrap_or_default();
|
|
|
|
let author = CACHE.get_or(&author_id, serde_json::Value::String(author_id.clone()));
|
2024-04-22 01:01:20 +02:00
|
|
|
let attachments = object.attachment()
|
2024-04-24 04:58:46 +02:00
|
|
|
.map(|x| {
|
|
|
|
let (expand, set_expand) = create_signal(false);
|
|
|
|
view! {
|
|
|
|
<p class="center">
|
|
|
|
<img
|
|
|
|
class="attachment ml-1"
|
|
|
|
class:expand=expand
|
|
|
|
src={x.url().id().unwrap_or_default()}
|
|
|
|
title={x.name().unwrap_or_default().to_string()}
|
|
|
|
on:click=move |_| set_expand.set(!expand.get())
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
}
|
2024-04-22 01:01:20 +02:00
|
|
|
})
|
|
|
|
.collect_view();
|
2024-04-23 23:28:19 +02:00
|
|
|
let attachments_padding = if object.attachment().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(view! { <div class="pb-1"></div> })
|
|
|
|
};
|
2024-04-21 17:43:36 +02:00
|
|
|
view! {
|
|
|
|
<table class="align w-100">
|
|
|
|
<tr>
|
|
|
|
<td><ActorBanner object=author /></td>
|
|
|
|
<td class="rev" >
|
2024-04-22 01:01:20 +02:00
|
|
|
{object.in_reply_to().id().map(|reply| view! {
|
2024-04-23 03:31:42 +02:00
|
|
|
<small><i><a class="clean" href={Uri::web(FetchKind::Object, &reply)} title={reply}>reply</a></i></small>
|
2024-04-22 01:01:20 +02:00
|
|
|
})}
|
2024-04-23 03:31:42 +02:00
|
|
|
<PrivacyMarker addressed=object.addressed() />
|
|
|
|
<a class="clean hover ml-s" href={Uri::web(FetchKind::Object, object.id().unwrap_or_default())}>
|
2024-04-21 17:43:36 +02:00
|
|
|
<DateTime t=object.published() />
|
|
|
|
</a>
|
2024-04-23 03:31:42 +02:00
|
|
|
<sup><small><a class="clean ml-s" href={uid} target="_blank">"↗"</a></small></sup>
|
2024-04-21 17:43:36 +02:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<blockquote class="tl">
|
2024-04-23 23:28:19 +02:00
|
|
|
<Summary summary=object.summary().map(|x| x.to_string()) >
|
|
|
|
{content.into_iter().map(|x| view! { <p>{x}</p> }).collect_view()}
|
|
|
|
{attachments_padding}
|
|
|
|
{attachments}
|
|
|
|
</Summary>
|
2024-04-21 17:43:36 +02:00
|
|
|
</blockquote>
|
2024-04-23 23:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn Summary(summary: Option<String>, children: Children) -> impl IntoView {
|
|
|
|
match summary.filter(|x| !x.is_empty()) {
|
|
|
|
None => children().into_view(),
|
|
|
|
Some(summary) => view! {
|
|
|
|
<details class="pa-s">
|
|
|
|
<summary>
|
|
|
|
<code class="cw color ml-s w-100">{summary}</code>
|
|
|
|
</summary>
|
|
|
|
{children()}
|
|
|
|
</details>
|
|
|
|
}.into_view(),
|
2024-04-21 17:43:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|