Skip to content

Commit

Permalink
feat: add toast when text is copied to clipboard and use default curs…
Browse files Browse the repository at this point in the history
…or (#625)
  • Loading branch information
hrzlgnm authored Dec 17, 2024
1 parent 3e1aef6 commit 34274d9
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ use shared_constants::{
SPLASH_SCREEN_DURATION, VERIFY_TIMEOUT,
};
use std::collections::HashSet;
use std::time::Duration;
use strsim::jaro_winkler;
use tauri_sys::core::invoke;
use tauri_sys::event::listen;
use thaw::mobile::{show_toast, ToastOptions};
use thaw::{
AutoComplete, AutoCompleteOption, AutoCompleteRef, AutoCompleteSuffix, Button, ButtonColor,
ButtonSize, ButtonVariant, Card, CardFooter, CardHeaderExtra, Collapse, CollapseItem,
Expand Down Expand Up @@ -359,27 +361,25 @@ fn CopyToClipBoardButton(
async move { copy_to_clipboard(input.clone()).await }
});

let on_copy_to_clibboard_click = move |_| {
let text = text_to_copy.get();
copy_to_clipboard_action.dispatch(text);
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),
});
};

view! {
<Button
disabled=disabled
on_click=on_copy_to_clibboard_click
on_click=on_copy_to_clipboard_click
color=ButtonColor::Success
variant=ButtonVariant::Outlined
size=ButtonSize::Small
class="copy-to-clipboard-cursor"
>
{button_text}
</Button>
<Style>
".copy-to-clipboard-cursor {
cursor: copy !important;
}"
</Style>
}
}

Expand All @@ -397,13 +397,13 @@ async fn copy_to_clipboard(contents: String) {
)
.await;
}
fn drop_trailing_dot(fqn: &str) -> String {
fqn.strip_suffix(".").unwrap_or(fqn).to_owned()
}

fn drop_local_and_last_dot(fqn: &str) -> String {
let without_local = fqn.strip_suffix(".local.").unwrap_or(fqn);
without_local
.strip_suffix(".")
.unwrap_or(without_local)
.to_owned()
drop_trailing_dot(without_local).to_owned()
}

/// Component that shows a resolved service as a card
Expand All @@ -428,6 +428,7 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView {
)
};

let to_copy_host = drop_trailing_dot(&resolved_service.hostname);
let short_host = drop_local_and_last_dot(&resolved_service.hostname);
let short_service_type = drop_local_and_last_dot(&resolved_service.service_type);

Expand Down Expand Up @@ -466,7 +467,7 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView {
<Space vertical=true>
<Space align=SpaceAlign::Center justify=SpaceJustify::Center>
<CopyToClipBoardButton
text=Some(resolved_service.hostname)
text=Some(to_copy_host.to_string())
button_text=Some(short_host)
disabled=resolved_service.dead
/>
Expand Down

0 comments on commit 34274d9

Please sign in to comment.