From 838e99fd1577c52121e148efabcd624114a8b9ad Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 11 Jun 2025 02:54:27 +0100 Subject: fmt: everything --- .../roster_list/contact_request_manager.rs | 221 +++++++++++++-------- 1 file changed, 141 insertions(+), 80 deletions(-) (limited to 'src/components/roster_list/contact_request_manager.rs') diff --git a/src/components/roster_list/contact_request_manager.rs b/src/components/roster_list/contact_request_manager.rs index 174e677..cfb5f28 100644 --- a/src/components/roster_list/contact_request_manager.rs +++ b/src/components/roster_list/contact_request_manager.rs @@ -1,12 +1,18 @@ use std::{collections::HashSet, str::FromStr}; -use filamento::{error::{CommandError, SubscribeError}, roster::ContactStoreFields}; +use filamento::{ + error::{CommandError, SubscribeError}, + roster::ContactStoreFields, +}; use jid::{BareJID, JID}; use leptos::{html::Input, prelude::*}; use reactive_stores::Store; use thiserror::Error; -use crate::{client::Client, roster::{Roster, RosterStoreFields}}; +use crate::{ + client::Client, + roster::{Roster, RosterStoreFields}, +}; #[derive(Clone, Debug, Error)] pub enum AddContactError { @@ -21,9 +27,11 @@ pub enum AddContactError { #[component] // TODO: rename pub fn AddContact() -> impl IntoView { - let requests: ReadSignal> = use_context().expect("no pending subscriptions in context"); - let set_requests: WriteSignal> = use_context().expect("no pending subscriptions write signal in context"); - let roster: Store = use_context().expect("no roster in context"); + let requests: ReadSignal> = + use_context().expect("no pending subscriptions in context"); + let set_requests: WriteSignal> = + use_context().expect("no pending subscriptions write signal in context"); + let roster: Store = use_context().expect("no roster in context"); let jid = RwSignal::new("".to_string()); // TODO: compartmentalise into error component, form component... @@ -44,7 +52,7 @@ pub fn AddContact() -> impl IntoView { let client3 = client.clone(); let client4 = client.clone(); - let add_contact= Action::new_local(move |_| { + let add_contact = Action::new_local(move |_| { let client = client.clone(); async move { set_add_contact_pending.set(true); @@ -71,8 +79,8 @@ pub fn AddContact() -> impl IntoView { Err(e) => { set_error.set(Some(e.into())); set_add_contact_pending.set(false); - return; - }, + return; + } }; set_add_contact_pending.set(false); @@ -90,19 +98,26 @@ pub fn AddContact() -> impl IntoView { } }); - let outgoing = move || roster.contacts().get().into_iter().filter(|(jid, contact)| { - match *contact.contact.subscription().read() { - filamento::roster::Subscription::None => false, - filamento::roster::Subscription::PendingOut => true, - filamento::roster::Subscription::PendingIn => false, - filamento::roster::Subscription::PendingInPendingOut => true, - filamento::roster::Subscription::OnlyOut => false, - filamento::roster::Subscription::OnlyIn => false, - filamento::roster::Subscription::OutPendingIn => false, - filamento::roster::Subscription::InPendingOut => true, - filamento::roster::Subscription::Buddy => false, - } - }).collect::>(); + let outgoing = move || { + roster + .contacts() + .get() + .into_iter() + .filter( + |(jid, contact)| match *contact.contact.subscription().read() { + filamento::roster::Subscription::None => false, + filamento::roster::Subscription::PendingOut => true, + filamento::roster::Subscription::PendingIn => false, + filamento::roster::Subscription::PendingInPendingOut => true, + filamento::roster::Subscription::OnlyOut => false, + filamento::roster::Subscription::OnlyIn => false, + filamento::roster::Subscription::OutPendingIn => false, + filamento::roster::Subscription::InPendingOut => true, + filamento::roster::Subscription::Buddy => false, + }, + ) + .collect::>() + }; let accept_friend_request = Action::new_local(move |jid: &BareJID| { let client = client2.clone(); @@ -129,70 +144,116 @@ pub fn AddContact() -> impl IntoView { async move { // TODO: error client.unsubscribe_from_contact(jid).await; - } }); view! {
-
- {error_message} -
- - -
-
- {move || if !requests.read().is_empty() { - view! { -
-

Incoming Subscription Requests

- - { - let request2 = request.clone(); - let request3 = request.clone(); - let jid_string = move || request.to_string(); - view! { -
{jid_string}
-
Accept
Reject
- } - } -
-
- }.into_any() - } else { - view! {}.into_any() - }} - {move || if !outgoing().is_empty() { - view! { -
-

Pending Outgoing Subscription Requests

- - { - let jid2 = jid.clone(); - let jid_string = move || jid.to_string(); - view! { -
{jid_string}
Cancel
- } - } -
-
- }.into_any() - } else { - view! {}.into_any() - }} +
+ {error_message} +
+ + +
+
+ {move || { + if !requests.read().is_empty() { + view! { +
+

Incoming Subscription Requests

+ + { + let request2 = request.clone(); + let request3 = request.clone(); + let jid_string = move || request.to_string(); + view! { +
+
{jid_string}
+
+
+ Accept +
+
+ Reject +
+
+
+ } + } +
+
+ } + .into_any() + } else { + view! {}.into_any() + } + }} + {move || { + if !outgoing().is_empty() { + view! { +
+

Pending Outgoing Subscription Requests

+ + { + let jid2 = jid.clone(); + let jid_string = move || jid.to_string(); + view! { +
+
{jid_string}
+
+ Cancel +
+
+ } + } +
+
+ } + .into_any() + } else { + view! {}.into_any() + } + }}
} } - -- cgit