feat(web): filter timelines, loop videos, open cws

This commit is contained in:
əlemi 2024-05-12 00:12:07 +02:00
parent c068822b3c
commit 227e9c625b
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 49 additions and 33 deletions

View file

@ -33,14 +33,25 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
}
#[component]
pub fn Item(item: crate::Object) -> impl IntoView {
pub fn Item(
item: crate::Object,
#[prop(optional)] sep: bool,
) -> impl IntoView {
let config = use_context::<Signal<crate::Config>>().expect("missing config context");
let id = item.id().unwrap_or_default().to_string();
let sep = if sep { Some(view! { <hr /> }) } else { None };
match item.object_type() {
// special case for placeholder activities
Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) =>
view! { <Object object=item /> }.into_view(),
Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => (move || {
if config.get().filters.orphans {
Some(view! { <Object object=item.clone() />{sep.clone()} })
} else {
None
}
}).into_view(),
// everything else
Some(apb::ObjectType::Activity(t)) => {
Some(apb::ObjectType::Activity(t)) => (move || {
if config.get().filters.visible(apb::ObjectType::Activity(t)) {
let object_id = item.object().id().unwrap_or_default();
let object = match t {
apb::ActivityType::Create | apb::ActivityType::Announce =>
@ -52,17 +63,21 @@ pub fn Item(item: crate::Object) -> impl IntoView {
view! {
<div class="ml-1">
<ActorBanner object=obj />
<FollowRequestButtons activity_id=id actor_id=object_id />
<FollowRequestButtons activity_id=id.clone() actor_id=object_id />
</div>
}
}.into_view()),
_ => None,
};
view! {
<ActivityLine activity=item />
Some(view! {
<ActivityLine activity=item.clone() />
{object}
}.into_view()
},
{sep.clone()}
})
} else {
None
}
}).into_view(),
// should never happen
_ => view! { <p><code>type not implemented</code></p> }.into_view(),
}

View file

@ -11,6 +11,7 @@ pub fn Attachment(
#[prop(optional)]
sensitive: bool
) -> impl IntoView {
let config = use_context::<Signal<crate::Config>>().expect("missing config context");
let (expand, set_expand) = create_signal(false);
let href = object.url().id().unwrap_or_default();
let media_type = object.media_type()
@ -47,7 +48,7 @@ pub fn Attachment(
on:click=move |_| set_expand.set(!expand.get())
title={object.name().unwrap_or_default().to_string()}
>
<video controls loop class="attachment" class:expand=expand >
<video controls class="attachment" class:expand=expand prop:loop=move || config.get().loop_videos >
{move || if sensitive && !expand.get() { None } else { Some(view! { <source src={_href.clone()} type={media_type.clone()} /> }) }}
<a href={href.clone()} target="_blank">video clip</a>
</video>
@ -58,7 +59,7 @@ pub fn Attachment(
"audio" =>
view! {
<p class="center">
<audio controls class="w-100">
<audio controls class="w-100" prop:loop=move || config.get().loop_videos >
<source src={href.clone()} type={media_type} />
<a href={href} target="_blank">audio clip</a>
</audio>
@ -106,7 +107,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
Some(view! { <div class="pb-1"></div> })
};
let post_inner = view! {
<Summary summary=object.summary().map(|x| x.to_string()) open=false >
<Summary summary=object.summary().map(|x| x.to_string()) >
<p inner_html={content}></p>
{attachments_padding}
{attachments}
@ -152,11 +153,12 @@ pub fn Object(object: crate::Object) -> impl IntoView {
}
#[component]
pub fn Summary(summary: Option<String>, open: bool, children: Children) -> impl IntoView {
pub fn Summary(summary: Option<String>, children: Children) -> impl IntoView {
let config = use_context::<Signal<crate::Config>>().expect("missing config context");
match summary.filter(|x| !x.is_empty()) {
None => children().into_view(),
Some(summary) => view! {
<details class="pa-s" prop:open=open>
<details class="pa-s" prop:open=move || !config.get().collapse_content_warnings>
<summary>
<code class="cw center color ml-s w-100">{summary}</code>
</summary>

View file

@ -140,8 +140,7 @@ pub fn TimelineFeed(tl: Timeline) -> impl IntoView {
children=move |id: String| {
match CACHE.get(&id) {
Some(i) => view! {
<Item item=i />
<hr />
<Item item=i sep=true />
}.into_view(),
None => view! {
<p><code>{id}</code>" "[<a href={uri}>go</a>]</p>