Skip to content

Commit

Permalink
Merge branch 'dev' into disable_deletion_files
Browse files Browse the repository at this point in the history
  • Loading branch information
stavares843 authored Mar 8, 2024
2 parents 262461e + 0c722e2 commit 6195c9d
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions ui/src/layouts/chats/presentation/chat/edit_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};

use common::{
icons::outline::Shape as Icon,
icons::Icon as IconElement,
language::get_local_text,
state::{Identity, State},
warp_runner::{RayGunCmd, WarpCmd},
Expand Down Expand Up @@ -45,6 +46,8 @@ pub fn EditGroup(cx: Scope) -> Element {
let edit_group_action = use_state(cx, || EditGroupAction::Remove);
let conv_id = state.read().get_active_chat().unwrap().id;

let creator_id = state.read().get_active_chat()?.creator.clone()?;

let friends_did_already_in_group = state.read().get_active_chat().unwrap().participants;

let friends_list: HashMap<DID, Identity> = HashMap::from_iter(
Expand Down Expand Up @@ -111,6 +114,9 @@ pub fn EditGroup(cx: Scope) -> Element {
}
});

let creator_did2 = creator_id.clone();
let am_i_group_creator = creator_id == state.read().did_key();

cx.render(rsx!(
div {
id: "edit-members",
Expand Down Expand Up @@ -162,13 +168,16 @@ pub fn EditGroup(cx: Scope) -> Element {
aria_label: "friend-group",
friends.iter().map(
|_friend| {
let is_group_creator = creator_did2.clone() == _friend.clone().did_key();
rsx!(
friend_row {
add_or_remove: if *edit_group_action.current() == EditGroupAction::Add {
"add".into()
} else {
"remove".into()
},
friend_is_group_creator: is_group_creator,
am_i_group_creator: am_i_group_creator,
friend: _friend.clone(),
minimal: minimal,
conv_id: conv_id,
Expand Down Expand Up @@ -196,6 +205,8 @@ pub fn EditGroup(cx: Scope) -> Element {
#[derive(Props, Eq, PartialEq)]
pub struct FriendRowProps {
add_or_remove: String,
friend_is_group_creator: bool,
am_i_group_creator: bool,
minimal: bool,
friend: Identity,
conv_id: Uuid,
Expand Down Expand Up @@ -272,34 +283,50 @@ fn friend_row(cx: Scope<FriendRowProps>) -> Element {
_friend.username(),
},
},
Button {
aria_label: if cx.props.add_or_remove == "add" {
get_local_text("uplink.add")
} else {
get_local_text("uplink.remove")
},
icon: if cx.props.add_or_remove == "add" {
Icon::UserPlus
} else {
Icon::UserMinus
},
text: if cx.props.minimal { String::new() }
else if cx.props.add_or_remove == "add" {
if cx.props.friend_is_group_creator {
rsx!(
div {
class: "group-creator-container",
IconElement {
icon: Icon::Satellite
}
span {
class: "group-creator-text",
get_local_text("messages.group-creator-label")
}
}
)
}
if cx.props.am_i_group_creator || cx.props.add_or_remove == "add" {
rsx!(Button {
aria_label: if cx.props.add_or_remove == "add" {
get_local_text("uplink.add")
} else {
get_local_text("uplink.remove")
}
,
onpress: move |_| {
let mut friends = selected_friends.get().clone();
friends.clear();
selected_friends.set(vec![_friend.did_key()].into_iter().collect());
if cx.props.add_or_remove == "add" {
ch.send(ChanCmd::AddParticipants);
},
icon: if cx.props.add_or_remove == "add" {
Icon::UserPlus
} else {
ch.send(ChanCmd::RemoveParticipants);
Icon::UserMinus
},
text: if cx.props.minimal { String::new() }
else if cx.props.add_or_remove == "add" {
get_local_text("uplink.add")
} else {
get_local_text("uplink.remove")
}
,
onpress: move |_| {
let mut friends = selected_friends.get().clone();
friends.clear();
selected_friends.set(vec![_friend.did_key()].into_iter().collect());
if cx.props.add_or_remove == "add" {
ch.send(ChanCmd::AddParticipants);
} else {
ch.send(ChanCmd::RemoveParticipants);
}
}
}
})
}
}
))
Expand Down

0 comments on commit 6195c9d

Please sign in to comment.