feat(web): hide sensitive posts, add posting option
This commit is contained in:
parent
ed0a4fd211
commit
6c92328b8d
3 changed files with 23 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::prelude::*;
|
use crate::{prelude::*, URL_SENSITIVE};
|
||||||
|
|
||||||
use apb::{target::Addressed, Base, Object};
|
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 content = dissolve::strip_html_tags(object.content().unwrap_or_default());
|
||||||
let author_id = object.attributed_to().id().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 author = CACHE.get_or(&author_id, serde_json::Value::String(author_id.clone()));
|
||||||
|
let sensitive = object.sensitive().unwrap_or_default();
|
||||||
let attachments = object.attachment()
|
let attachments = object.attachment()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
let (expand, set_expand) = create_signal(false);
|
let (expand, set_expand) = create_signal(false);
|
||||||
|
let href = x.url().id().unwrap_or_default();
|
||||||
view! {
|
view! {
|
||||||
<p class="center">
|
<p class="center">
|
||||||
<img
|
<img
|
||||||
class="attachment ml-1"
|
class="attachment ml-1"
|
||||||
class:expand=expand
|
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()}
|
title={x.name().unwrap_or_default().to_string()}
|
||||||
on:click=move |_| set_expand.set(!expand.get())
|
on:click=move |_| set_expand.set(!expand.get())
|
||||||
/>
|
/>
|
||||||
|
@ -48,7 +54,7 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<blockquote class="tl">
|
<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()}
|
{content.into_iter().map(|x| view! { <p>{x}</p> }).collect_view()}
|
||||||
{attachments_padding}
|
{attachments_padding}
|
||||||
{attachments}
|
{attachments}
|
||||||
|
@ -58,11 +64,11 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[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()) {
|
match summary.filter(|x| !x.is_empty()) {
|
||||||
None => children().into_view(),
|
None => children().into_view(),
|
||||||
Some(summary) => view! {
|
Some(summary) => view! {
|
||||||
<details class="pa-s">
|
<details class="pa-s" prop:open=open>
|
||||||
<summary>
|
<summary>
|
||||||
<code class="cw color ml-s w-100">{summary}</code>
|
<code class="cw color ml-s w-100">{summary}</code>
|
||||||
</summary>
|
</summary>
|
||||||
|
|
|
@ -95,6 +95,7 @@ pub fn AdvancedPostBox(username: Signal<Option<String>>, advanced: WriteSignal<b
|
||||||
let (error, set_error) = create_signal(None);
|
let (error, set_error) = create_signal(None);
|
||||||
let (value, set_value) = create_signal("Like".to_string());
|
let (value, set_value) = create_signal("Like".to_string());
|
||||||
let (embedded, set_embedded) = create_signal(false);
|
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 summary_ref: NodeRef<html::Input> = create_node_ref();
|
||||||
let content_ref: NodeRef<html::Textarea> = create_node_ref();
|
let content_ref: NodeRef<html::Textarea> = create_node_ref();
|
||||||
let context_ref: NodeRef<html::Input> = 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" />
|
<input class="w-100" type="text" node_ref=object_id_ref title="objectId" placeholder="objectId" />
|
||||||
|
|
||||||
<div class:hidden=move|| !embedded.get()>
|
<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=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=context_ref title="context" placeholder="context" />
|
||||||
<input class="w-100" type="text" node_ref=reply_ref title="inReplyTo" placeholder="inReplyTo" />
|
<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>
|
<textarea rows="5" class="w-100" node_ref=content_ref title="content" placeholder="content" ></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ pub mod prelude;
|
||||||
|
|
||||||
pub const URL_BASE: &str = "https://feditest.alemi.dev";
|
pub const URL_BASE: &str = "https://feditest.alemi.dev";
|
||||||
pub const URL_PREFIX: &str = "/web";
|
pub const URL_PREFIX: &str = "/web";
|
||||||
|
pub const URL_SENSITIVE: &str = "https://cdn.alemi.dev/social/nsfw.png";
|
||||||
pub const NAME: &str = "μ";
|
pub const NAME: &str = "μ";
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
Loading…
Reference in a new issue