From 9faae6f6278244fdb543c5b4672f88da5ab4b460 Mon Sep 17 00:00:00 2001
From: alemi
Date: Mon, 29 Apr 2024 02:33:21 +0200
Subject: [PATCH] feat(web): show audio, video and generic attachments
not only images anymore!!!
---
web/index.html | 20 +++++++--
web/src/components/object.rs | 82 ++++++++++++++++++++++++++++++------
2 files changed, 85 insertions(+), 17 deletions(-)
diff --git a/web/index.html b/web/index.html
index bf7c59da..11399852 100644
--- a/web/index.html
+++ b/web/index.html
@@ -154,23 +154,37 @@
img.inline-avatar {
max-height: 2em;
}
+ p.box {
+ border: 3px solid #bf616a;
+ width: 100%;
+ }
+ p.cursor {
+ cursor: pointer;
+ }
+ video.attachment {
+ height: 10em;
+ }
img.attachment {
cursor: pointer;
height: 10em;
width: 100%;
- border: 5px solid #bf616a;
+ border: 3px solid #bf616a;
padding: 5px;
object-fit: cover;
}
- img.expand {
+ img.expand,
+ video.expand {
height: unset;
- max-height: 50vh;
+ max-height: 55vh;
object-fit: contain;
}
div.tl-header {
background-color: #bf616a55;
color: #bf616a;
}
+ p.tiny-text {
+ line-height: .75em;
+ }
table.post-table {
border-collapse: collapse;
}
diff --git a/web/src/components/object.rs b/web/src/components/object.rs
index ad6c9c44..b41e2a20 100644
--- a/web/src/components/object.rs
+++ b/web/src/components/object.rs
@@ -3,18 +3,25 @@ use crate::{prelude::*, URL_SENSITIVE};
use apb::{target::Addressed, Base, Object};
-
#[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| {
- let (expand, set_expand) = create_signal(false);
- let href = x.url().id().unwrap_or_default();
+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! {
impl IntoView {
} else {
href.clone()
}}
- title={x.name().unwrap_or_default().to_string()}
+ title={object.name().unwrap_or_default().to_string()}
on:click=move |_| set_expand.set(!expand.get())
/>
- }
- })
+ }.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 attachments_padding = if object.attachment().is_empty() {
None