Skip to content

Commit

Permalink
feat(chat): Add toasts to various quickprofile actions (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flemmli97 authored Apr 5, 2024
1 parent 0cbe129 commit 8142b4f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
3 changes: 3 additions & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ friends = Friends
.block = Block
.all = All Friends
.remove = Unfriend
.removed = Removed user from friends
.edit-group = Edit Group
.manage-group-members = Manage Members
.view-group = View Group
Expand All @@ -144,13 +145,15 @@ friends = Friends
.pending = Pending
.key-blocked = User Blocked
.blocked = Blocked
.blocked-action = Blocked user
.accept = Accept
.deny = Deny Request
.request-sent = Friend Request Sent!
.new-request = New friend request.
.new-request-name = { $name } sent a request.
.copied-did = Copied ID to clipboard!
.unblock = Unblock
.unblocked = Unblocked user.
.request-exist = Friend request is already pending!
.add-name = Add { $name }
.already-friends = Already Friends
Expand Down
63 changes: 53 additions & 10 deletions ui/src/layouts/chats/presentation/quick_profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,20 @@ pub fn QuickProfileContext<'a>(cx: Scope<'a, QuickProfileProps<'a>>) -> Element<
}

let rsp = rx.await.expect("command canceled");
if let Err(e) = rsp {
log::error!("failed to remove friend: {}", e);
match rsp {
Ok(_) => {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text("friends.removed"),
None,
2,
),
));
}
Err(e) => {
log::error!("failed to remove friend: {}", e);
}
}
}
QuickProfileCmd::BlockFriend(did) => {
Expand All @@ -184,9 +196,20 @@ pub fn QuickProfileContext<'a>(cx: Scope<'a, QuickProfileProps<'a>>) -> Element<
}

let rsp = rx.await.expect("command canceled");
if let Err(e) = rsp {
// todo: display message to user
log::error!("failed to block friend: {}", e);
match rsp {
Ok(_) => {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text("friends.blocked-action"),
None,
2,
),
));
}
Err(e) => {
log::error!("failed to block friend: {}", e);
}
}
}
QuickProfileCmd::UnBlockFriend(did) => {
Expand All @@ -199,9 +222,20 @@ pub fn QuickProfileContext<'a>(cx: Scope<'a, QuickProfileProps<'a>>) -> Element<
}

let rsp = rx.await.expect("command canceled");
if let Err(e) = rsp {
// todo: display message to user
log::error!("failed to unblock friend: {}", e);
match rsp {
Ok(_) => {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text("friends.unblocked"),
None,
2,
),
));
}
Err(e) => {
log::error!("failed to unblock friend: {}", e);
}
}
}
QuickProfileCmd::RemoveDirectConvs(recipient) => {
Expand Down Expand Up @@ -289,7 +323,16 @@ pub fn QuickProfileContext<'a>(cx: Scope<'a, QuickProfileProps<'a>>) -> Element<
}));
let res = rx.await.expect("failed to get response from warp_runner");
match res {
Ok(_) => {}
Ok(_) => {
state.write().mutate(Action::AddToastNotification(
ToastNotification::init(
"".into(),
get_local_text("friends.request-sent"),
None,
2,
),
));
}
Err(e) => match e {
Error::PublicKeyIsBlocked => {
log::warn!("add friend failed: {}", e);
Expand Down Expand Up @@ -338,7 +381,7 @@ pub fn QuickProfileContext<'a>(cx: Scope<'a, QuickProfileProps<'a>>) -> Element<
p {
class: "text",
aria_label: "profile-name-value",
format!("{}", identity.username())
format!("{}", if identity.username().is_empty() { get_local_text("uplink.unknown") } else { identity.username() })
}
}
identity.status_message().and_then(|s|{
Expand Down

0 comments on commit 8142b4f

Please sign in to comment.