Skip to content

Commit fbbcaaf

Browse files
Add share raw JWT button (#77)
1 parent 263b388 commit fbbcaaf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/jwt.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::str::FromStr;
1010

1111
use web_sys::{HtmlInputElement, KeyboardEvent};
1212
use yew::{function_component, html, use_effect_with, use_state, Callback, Html, TargetCast};
13-
use yew_hooks::{use_local_storage, use_location};
13+
use yew_hooks::{use_clipboard, use_local_storage, use_location};
1414
use yew_notifications::{use_notification, Notification, NotificationType};
1515

1616
use crate::common::Checkbox;
@@ -162,6 +162,18 @@ pub fn jwt() -> Html {
162162
}
163163
});
164164

165+
let jwt_to_copy = (*raw_jwt).clone();
166+
let notifications = use_notification::<Notification>();
167+
let clipboard = use_clipboard();
168+
let share_by_link = Callback::from(move |_| {
169+
clipboard.write_text(jwt_to_copy.clone());
170+
171+
notifications.spawn(Notification::from_description_and_type(
172+
NotificationType::Info,
173+
"link to jwt copied",
174+
));
175+
});
176+
165177
html! {
166178
<article class="vertical">
167179
<textarea
@@ -175,6 +187,9 @@ pub fn jwt() -> Html {
175187
<div class="horizontal">
176188
<button class="action-button" {onclick}>{"Process"}</button>
177189
<Checkbox id={"auto-decode".to_owned()} name={"auto-decode".to_owned()} checked={*auto_decode} {set_checked} />
190+
<button class="button-with-icon" onclick={share_by_link}>
191+
<img src="/public/img/icons/share_by_link.png" />
192+
</button>
178193
</div>
179194
{if let Some(jwte) = &(*jwte) {
180195
match jwte {

0 commit comments

Comments
 (0)