feat(web): hide sensitive posts, add posting option

This commit is contained in:
əlemi 2024-04-24 05:38:09 +02:00
parent ed0a4fd211
commit 6c92328b8d
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 23 additions and 7 deletions

View file

@ -1,5 +1,5 @@
use leptos::*;
use crate::prelude::*;
use crate::{prelude::*, URL_SENSITIVE};
use apb::{target::Addressed, Base, Object};
@ -10,15 +10,21 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
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();
view! {
<p class="center">
<img
class="attachment ml-1"
class:expand=expand
src={x.url().id().unwrap_or_default()}
src={move || if sensitive && !expand.get() {
URL_SENSITIVE.to_string()
} else {
href.clone()
}}
title={x.name().unwrap_or_default().to_string()}
on:click=move |_| set_expand.set(!expand.get())
/>
@ -48,7 +54,7 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
</tr>
</table>
<blockquote class="tl">
<Summary summary=object.summary().map(|x| x.to_string()) >
<Summary summary=object.summary().map(|x| x.to_string()) open=!sensitive >
{content.into_iter().map(|x| view! { <p>{x}</p> }).collect_view()}
{attachments_padding}
{attachments}
@ -58,11 +64,11 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
}
#[component]
pub fn Summary(summary: Option<String>, children: Children) -> impl IntoView {
pub fn Summary(summary: Option<String>, open: bool, children: Children) -> impl IntoView {
match summary.filter(|x| !x.is_empty()) {
None => children().into_view(),
Some(summary) => view! {
<details class="pa-s">
<details class="pa-s" prop:open=open>
<summary>
<code class="cw color ml-s w-100">{summary}</code>
</summary>

View file

@ -95,6 +95,7 @@ pub fn AdvancedPostBox(username: Signal<Option<String>>, advanced: WriteSignal<b
let (error, set_error) = create_signal(None);
let (value, set_value) = create_signal("Like".to_string());
let (embedded, set_embedded) = create_signal(false);
let sensitive_ref: NodeRef<html::Input> = create_node_ref();
let summary_ref: NodeRef<html::Input> = create_node_ref();
let content_ref: NodeRef<html::Textarea> = create_node_ref();
let context_ref: NodeRef<html::Input> = create_node_ref();
@ -139,12 +140,20 @@ pub fn AdvancedPostBox(username: Signal<Option<String>>, advanced: WriteSignal<b
<input class="w-100" type="text" node_ref=object_id_ref title="objectId" placeholder="objectId" />
<div class:hidden=move|| !embedded.get()>
<input class="w-100" type="text" node_ref=summary_ref title="summary" placeholder="summary" />
<input class="w-100" type="text" node_ref=name_ref title="name" placeholder="name" />
<input class="w-100" type="text" node_ref=context_ref title="context" placeholder="context" />
<input class="w-100" type="text" node_ref=reply_ref title="inReplyTo" placeholder="inReplyTo" />
<table class="align w-100">
<tr>
<td><input type="checkbox" title="sensitive" checked node_ref=sensitive_ref/>
</td>
<td class="w-100">
<input class="w-100" type="text" node_ref=summary_ref title="summary" placeholder="summary" />
</td>
</tr>
</table>
<textarea rows="5" class="w-100" node_ref=content_ref title="content" placeholder="content" ></textarea>
</div>

View file

@ -10,6 +10,7 @@ pub mod prelude;
pub const URL_BASE: &str = "https://feditest.alemi.dev";
pub const URL_PREFIX: &str = "/web";
pub const URL_SENSITIVE: &str = "https://cdn.alemi.dev/social/nsfw.png";
pub const NAME: &str = "μ";
use std::sync::Arc;