feat(web): repost button, fixed like button to/cc
This commit is contained in:
parent
0bfa49fed6
commit
be1c379477
1 changed files with 42 additions and 17 deletions
|
@ -96,7 +96,6 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
|
||||||
.map_or(0, |x| x.total_items().unwrap_or(0));
|
.map_or(0, |x| x.total_items().unwrap_or(0));
|
||||||
let already_liked = object.audience().get()
|
let already_liked = object.audience().get()
|
||||||
.map_or(false, |x| !x.ordered_items().is_empty());
|
.map_or(false, |x| !x.ordered_items().is_empty());
|
||||||
let like_target = if public { None } else { Some(author_id) };
|
|
||||||
let attachments_padding = if object.attachment().is_empty() {
|
let attachments_padding = if object.attachment().is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,8 +126,8 @@ pub fn Object(object: serde_json::Value) -> impl IntoView {
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<div class="mt-s ml-1 rev">
|
<div class="mt-s ml-1 rev">
|
||||||
<ReplyButton n=comments />
|
<ReplyButton n=comments />
|
||||||
<LikeButton n=likes liked=already_liked target=oid author=like_target />
|
<LikeButton n=likes liked=already_liked target=oid.clone() author=author_id private=!public />
|
||||||
<RepostButton n=shares />
|
<RepostButton n=shares target=oid />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,8 +152,9 @@ pub fn LikeButton(
|
||||||
n: u64,
|
n: u64,
|
||||||
target: String,
|
target: String,
|
||||||
liked: bool,
|
liked: bool,
|
||||||
#[prop(default=None)]
|
author: String,
|
||||||
author: Option<String>,
|
#[prop(optional)]
|
||||||
|
private: bool,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
let (count, set_count) = create_signal(n);
|
let (count, set_count) = create_signal(n);
|
||||||
let (clicked, set_clicked) = create_signal(!liked);
|
let (clicked, set_clicked) = create_signal(!liked);
|
||||||
|
@ -167,11 +167,12 @@ pub fn LikeButton(
|
||||||
on:click=move |_ev| {
|
on:click=move |_ev| {
|
||||||
if !clicked.get() { return; }
|
if !clicked.get() { return; }
|
||||||
let target_url = format!("{URL_BASE}/users/test/outbox");
|
let target_url = format!("{URL_BASE}/users/test/outbox");
|
||||||
let followers_url = format!("{URL_BASE}/users/test/followers");
|
let to = apb::Node::links(vec![author.to_string()]);
|
||||||
let (to, cc) = if let Some(author) = &author {
|
let cc = if private { apb::Node::Empty } else {
|
||||||
(apb::Node::links(vec![author.to_string()]), apb::Node::Empty)
|
apb::Node::links(vec![
|
||||||
} else {
|
apb::target::PUBLIC.to_string(),
|
||||||
(apb::Node::links(vec![apb::target::PUBLIC.to_string()]), apb::Node::links(vec![followers_url]))
|
format!("{URL_BASE}/users/test/followers")
|
||||||
|
])
|
||||||
};
|
};
|
||||||
let payload = serde_json::Value::Object(serde_json::Map::default())
|
let payload = serde_json::Value::Object(serde_json::Map::default())
|
||||||
.set_activity_type(Some(apb::ActivityType::Like))
|
.set_activity_type(Some(apb::ActivityType::Like))
|
||||||
|
@ -208,13 +209,37 @@ pub fn ReplyButton(n: u64) -> impl IntoView {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn RepostButton(n: u64) -> impl IntoView {
|
pub fn RepostButton(n: u64, target: String) -> impl IntoView {
|
||||||
let shares = if n > 0 {
|
let (count, set_count) = create_signal(n);
|
||||||
Some(view! { <small>{n}</small> })
|
let (clicked, set_clicked) = create_signal(true);
|
||||||
} else {
|
let auth = use_context::<Auth>().expect("missing auth context");
|
||||||
None
|
|
||||||
};
|
|
||||||
view! {
|
view! {
|
||||||
<span class="emoji ml-2">{shares}" 🚀"</span>
|
<span
|
||||||
|
class:emoji=clicked
|
||||||
|
class:cursor=clicked
|
||||||
|
class="emoji-btn ml-2"
|
||||||
|
on:click=move |_ev| {
|
||||||
|
if !clicked.get() { return; }
|
||||||
|
set_clicked.set(false);
|
||||||
|
let target_url = format!("{URL_BASE}/users/test/outbox");
|
||||||
|
let to = apb::Node::links(vec![apb::target::PUBLIC.to_string()]);
|
||||||
|
let cc = apb::Node::links(vec![format!("{URL_BASE}/users/test/followers")]);
|
||||||
|
let payload = serde_json::Value::Object(serde_json::Map::default())
|
||||||
|
.set_activity_type(Some(apb::ActivityType::Announce))
|
||||||
|
.set_object(apb::Node::link(target.clone()))
|
||||||
|
.set_to(to)
|
||||||
|
.set_cc(cc);
|
||||||
|
spawn_local(async move {
|
||||||
|
match Http::post(&target_url, &payload, auth).await {
|
||||||
|
Ok(()) => set_count.set(count.get() + 1),
|
||||||
|
Err(e) => tracing::error!("failed sending like: {e}"),
|
||||||
|
}
|
||||||
|
set_clicked.set(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{move || if count.get() > 0 { Some(view! { <small>{count}</small> })} else { None }}
|
||||||
|
" 🚀"
|
||||||
|
</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue