fix(web): buttons are not reactive until logged in

This commit is contained in:
əlemi 2024-05-01 16:55:02 +02:00
parent c059f664ac
commit d1760f2637
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -162,9 +162,11 @@ pub fn LikeButton(
view! { view! {
<span <span
class:emoji=clicked class:emoji=clicked
class:cursor=clicked class:emoji-btn=move || auth.get().is_some()
class="emoji-btn ml-2" class:cursor=move || clicked.get() && auth.get().is_some()
class="ml-2"
on:click=move |_ev| { on:click=move |_ev| {
if auth.get().is_none() { return; }
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 to = apb::Node::links(vec![author.to_string()]); let to = apb::Node::links(vec![author.to_string()]);
@ -199,6 +201,7 @@ pub fn LikeButton(
#[component] #[component]
pub fn ReplyButton(n: u64, target: String) -> impl IntoView { pub fn ReplyButton(n: u64, target: String) -> impl IntoView {
let reply = use_context::<ReplyControls>().expect("missing reply controls context"); let reply = use_context::<ReplyControls>().expect("missing reply controls context");
let auth = use_context::<Auth>().expect("missing auth context");
let comments = if n > 0 { let comments = if n > 0 {
Some(view! { <small>{n}</small> }) Some(view! { <small>{n}</small> })
} else { } else {
@ -208,8 +211,11 @@ pub fn ReplyButton(n: u64, target: String) -> impl IntoView {
view! { view! {
<span <span
class:emoji=move || !reply.reply_to.get().map_or(false, |x| x == _target) class:emoji=move || !reply.reply_to.get().map_or(false, |x| x == _target)
class="emoji-btn cursor ml-2" // TODO can we merge these two classes conditions?
on:click=move |_ev| reply.reply(&target) class:emoji-btn=move || auth.get().is_some()
class:cursor=move || auth.get().is_some()
class="ml-2"
on:click=move |_ev| if auth.get().is_some() { reply.reply(&target) }
> >
{comments} {comments}
" 📨" " 📨"
@ -225,9 +231,11 @@ pub fn RepostButton(n: u64, target: String) -> impl IntoView {
view! { view! {
<span <span
class:emoji=clicked class:emoji=clicked
class:cursor=clicked class:emoji-btn=move || auth.get().is_some()
class="emoji-btn ml-2" class:cursor=move || clicked.get() && auth.get().is_some()
class="ml-2"
on:click=move |_ev| { on:click=move |_ev| {
if auth.get().is_none() { return; }
if !clicked.get() { return; } if !clicked.get() { return; }
set_clicked.set(false); set_clicked.set(false);
let target_url = format!("{URL_BASE}/users/test/outbox"); let target_url = format!("{URL_BASE}/users/test/outbox");