Skip to content

Commit

Permalink
feat(Messages): Adds copy text option to message context menu (#1490)
Browse files Browse the repository at this point in the history
Co-authored-by: Darius Clark <dariusc93@users.noreply.github.com>
Co-authored-by: Sara Tavares <29093946+stavares843@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 9, 2023
1 parent fce92d6 commit f11d18e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions common/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ uplink = Uplink
.date-time-format = %d/%m/%Y %I:%M %p
.open-devtools = Open Console
.clear-unreads = Clear Unreads
.copy-text = Copy Text
community = Community
.invited = You're Invited!
Expand Down
12 changes: 10 additions & 2 deletions ui/src/components/friends/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ pub fn AddFriend(cx: Scope) -> Element {
}

if let Some(id) = my_id.get().clone() {
let mut clipboard = Clipboard::new().unwrap();
clipboard.set_text(id).unwrap();
match Clipboard::new() {
Ok(mut c) => {
if let Err(e) = c.set_text(id) {
log::warn!("Unable to set text to clipboard: {e}");
}
}
Err(e) => {
log::warn!("Unable to create clipboard reference: {e}");
}
};
state
.write()
.mutate(Action::AddToastNotification(ToastNotification::init(
Expand Down
12 changes: 10 additions & 2 deletions ui/src/components/settings/sub_pages/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,16 @@ pub fn ProfileSettings(cx: Scope) -> Element {
}
)),
onpress: move |_| {
let mut clipboard = Clipboard::new().unwrap();
clipboard.set_text(did_string.clone()).unwrap();
match Clipboard::new() {
Ok(mut c) => {
if let Err(e) = c.set_text(did_string.clone()) {
log::warn!("Unable to set text to clipboard: {e}");
}
},
Err(e) => {
log::warn!("Unable to create clipboard reference: {e}");
}
};
state
.write()
.mutate(Action::AddToastNotification(ToastNotification::init(
Expand Down
2 changes: 1 addition & 1 deletion ui/src/extension_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn ExtensionsBrowser(cx: Scope) -> Element {
let routes = vec![
Route {
name: get_local_text("settings-extensions.installed"),
icon: Icon::CheckCircle,
icon: Icon::Check,
to: "installed",
..Default::default()
},
Expand Down
19 changes: 19 additions & 0 deletions ui/src/layouts/chats/presentation/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
path::PathBuf,
};

use arboard::Clipboard;
use dioxus::prelude::{EventHandler, *};

mod coroutines;
Expand Down Expand Up @@ -399,6 +400,24 @@ fn wrap_messages_in_context_menu<'a>(cx: Scope<'a, MessagesProps<'a>>) -> Elemen
state.write().mutate(Action::SetEmojiPickerVisible(true));
}
},
ContextItem {
icon: Icon::ClipboardDocument,
aria_label: "messages-copy".into(),
text: get_local_text("uplink.copy-text"),
onpress: move |_| {
let text = message.inner.lines().join("\n");
match Clipboard::new() {
Ok(mut c) => {
if let Err(e) = c.set_text(text) {
log::warn!("Unable to set text to clipboard: {e}");
}
}
Err(e) => {
log::warn!("Unable to create clipboard reference: {e}");
}
};
}
},
ContextItem {
icon: Icon::Pencil,
aria_label: "messages-edit".into(),
Expand Down

0 comments on commit f11d18e

Please sign in to comment.