Skip to content

Commit

Permalink
Issue-289: add toast for clipboard copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
voelkera authored and mbfm committed Aug 29, 2024
1 parent 14ae134 commit f0a2815
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ tracing-web = { version = "0.1.3" }
url = "2.5.0"
uuid = "1.8.0"
walkdir = "2.4.0"
wasm-bindgen-futures = "0.4.43"
wasm-bindgen-test = "0.3.37"
which = "6.0.0"
zip = "2.1.3"

Expand Down
3 changes: 2 additions & 1 deletion opendut-lea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ tracing-subscriber = { workspace = true, features = ["ansi"] }
tracing-web = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }
wasm-bindgen-futures = { workspace = true }

[build-dependencies]
shadow-rs = { workspace = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.37"
wasm-bindgen-test = { workspace = true }

[lints]
workspace = true
6 changes: 2 additions & 4 deletions opendut-lea/src/downloads/cleo_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::app::{use_app_globals, ExpectGlobals};
use opendut_auth::public::OptionalAuthData;
use opendut_types::proto::util::VersionInfo;
use crate::components::{ButtonColor, ButtonStateSignalProvider, SimpleButton};
use crate::util::clipboard::copy_with_feedback;

#[component]
pub fn CleoCard(
Expand Down Expand Up @@ -94,10 +95,7 @@ pub fn CleoCard(
<button
class="button is-light"
title="Copy to clipboard"
on:click=move |_| {
let clipboard = window().navigator().clipboard();
let _ = clipboard.write_text(&clipboard_text);
}
on:click=move |_| { copy_with_feedback().dispatch(clipboard_text.clone()) }
>
<span class="icon">
<i class="fa-regular fa-copy"></i>
Expand Down
2 changes: 1 addition & 1 deletion opendut-lea/src/peers/configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn PeerConfigurator() -> impl IntoView {
let amount_clusters = cluster_view_list.len();

if amount_clusters > 0 {
let comma_separated_cluster_views = util::view_helper::join_with_comma_spans(cluster_view_list.clone());
let comma_separated_cluster_views = util::view::join_with_comma_spans(cluster_view_list.clone());
view! {
<div class="mb-3">"Configured in " {amount_clusters} " clusters: " {comma_separated_cluster_views}</div>
}
Expand Down
8 changes: 3 additions & 5 deletions opendut-lea/src/peers/configurator/tabs/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use leptos::{component, create_local_resource, IntoView, ReadSignal, RwSignal, SignalGet, SignalSet, use_context, view, WriteSignal, window};
use leptos::{component, create_local_resource, IntoView, ReadSignal, RwSignal, SignalGet, SignalSet, use_context, view, WriteSignal};
use opendut_auth::public::OptionalAuthData;

use opendut_types::peer::PeerId;
Expand All @@ -7,6 +7,7 @@ use crate::app::{ExpectGlobals, use_app_globals};
use crate::components::{ButtonColor, SimpleButton};
use crate::components::ButtonStateSignalProvider;
use crate::peers::configurator::types::UserPeerConfiguration;
use crate::util::clipboard::{copy_with_feedback};

#[component]
pub fn SetupTab(peer_configuration: ReadSignal<UserPeerConfiguration>) -> impl IntoView {
Expand Down Expand Up @@ -53,10 +54,7 @@ pub fn SetupTab(peer_configuration: ReadSignal<UserPeerConfiguration>) -> impl I
<button
class="button is-light"
title="Copy to clipboard"
on:click=move |_| {
let clipboard = window().navigator().clipboard();
let _ = clipboard.write_text(&clipboard_text);
}
on:click=move |_| { copy_with_feedback().dispatch(clipboard_text.clone()) }
>
<span class="icon">
<i class="fa-regular fa-copy"></i>
Expand Down
2 changes: 1 addition & 1 deletion opendut-lea/src/peers/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn Row(
}.into_view()
}).collect();

util::view_helper::join_with_comma_spans(cluster_view_list)
util::view::join_with_comma_spans(cluster_view_list)
});

view! {
Expand Down
29 changes: 29 additions & 0 deletions opendut-lea/src/util/clipboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use leptos::{create_action, window, Action};
use crate::components::{use_toaster, Toast};

pub fn copy_with_feedback() -> Action<String, ()> {
create_action(move |clipboard_text: &String| {
let toaster = use_toaster();
let test = clipboard_text.clone();
async move {
let clipboard = window().navigator().clipboard();
let clipboard_promise = clipboard.write_text(&test);
match wasm_bindgen_futures::JsFuture::from(clipboard_promise).await {
Ok(_) => {
toaster.toast(
Toast::builder()
.simple("Successfully copied Setup-String.")
.success(),
);
}
Err(_) => {
toaster.toast(
Toast::builder()
.simple("Error while copying Setup-String.")
.error(),
);
}
};
}
})
}
3 changes: 2 additions & 1 deletion opendut-lea/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod url;
mod ior;
mod tick;
pub mod net;
pub mod view_helper;
pub mod view;
pub mod clipboard;

pub const NON_BREAKING_SPACE: &str = "\u{a0}";
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pub fn join_with_comma_spans(elements: Vec<View>) -> Vec<View> {
}
}
elements_with_separator
}
}

0 comments on commit f0a2815

Please sign in to comment.