Skip to content

Commit

Permalink
feat: only show toast about copied text on desktop plaforms (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrzlgnm authored Dec 17, 2024
1 parent 87a359b commit 88e9088
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ fn CopyToClipBoardButton(
button_text: Option<String>,
#[prop(optional, into)] disabled: MaybeSignal<bool>,
) -> impl IntoView {
let is_desktop = use_context::<IsDesktopSignal>()
.expect("is_desktop context to exist")
.0;
let (text_to_copy, _) = create_signal(text.clone().unwrap_or_default());
let copy_to_clipboard_action = create_action(|input: &String| {
let input = input.clone();
Expand All @@ -364,10 +367,12 @@ fn CopyToClipBoardButton(
let on_copy_to_clipboard_click = move |_| {
let text = text_to_copy.get_untracked();
copy_to_clipboard_action.dispatch(text.clone());
show_toast(ToastOptions {
message: format!("Copied {} to clipboard", text),
duration: Duration::from_millis(2000),
});
if is_desktop.get_untracked() {
show_toast(ToastOptions {
message: format!("Copied {} to clipboard", text),
duration: Duration::from_millis(2000),
});
}
};

view! {
Expand Down

0 comments on commit 88e9088

Please sign in to comment.