From 0b6903fcccb5ca8fca17b7154e52b5e79fddd919 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 31 Jul 2024 21:47:38 -0400 Subject: [PATCH] Feat: Add `renotify` field to `UseWebNotificationOptions` and `ShowOptions` Uncommented the existing `renotify` code. --- examples/use_web_notification/src/main.rs | 2 +- src/use_web_notification.rs | 33 ++++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/use_web_notification/src/main.rs b/examples/use_web_notification/src/main.rs index bc717bb..3e06f56 100644 --- a/examples/use_web_notification/src/main.rs +++ b/examples/use_web_notification/src/main.rs @@ -14,7 +14,7 @@ fn Demo() -> impl IntoView { .title("Hello World from leptos-use") .direction(NotificationDirection::Auto) .language("en") - // .renotify(true) + .renotify(true) .tag("test"), ); diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 11fd21a..8870a89 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -28,6 +28,7 @@ use std::rc::Rc; /// UseWebNotificationOptions::default() /// .direction(NotificationDirection::Auto) /// .language("en") +/// .renotity(true) /// .tag("test"), /// ); /// @@ -227,8 +228,7 @@ impl From for web_sys::NotificationDirection { /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// /// The following implementations are missing: -/// - `renotify` -/// - `vibrate` +/// - `vibrate` /// - `silent` /// - `image` #[derive(DefaultBuilder, Clone)] @@ -268,10 +268,11 @@ pub struct UseWebNotificationOptions { /// user clicks or dismisses it, rather than closing automatically. require_interaction: bool, - // /// A boolean value specifying whether the user should be notified after a new notification replaces an old one. - // /// The default is `false`, which means they won't be notified. If `true`, then `tag` also must be set. - // #[builder(into)] - // renotify: bool, + /// A boolean value specifying whether the user should be notified after a new notification replaces an old one. + /// The default is `false`, which means they won't be notified. If `true`, then `tag` also must be set. + #[builder(into)] + renotify: bool, + /// Called when the user clicks on displayed `Notification`. on_click: Rc, @@ -296,7 +297,7 @@ impl Default for UseWebNotificationOptions { tag: None, icon: None, require_interaction: false, - // renotify: false, + renotify: false, on_click: Rc::new(|_| {}), on_close: Rc::new(|_| {}), on_error: Rc::new(|_| {}), @@ -311,8 +312,8 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options .dir(options.direction.into()) - .require_interaction(options.require_interaction); - // .renotify(options.renotify); + .require_interaction(options.require_interaction) + .renotify(options.renotify); if let Some(body) = &options.body { web_sys_options.body(body); @@ -380,10 +381,10 @@ pub struct ShowOptions { /// user clicks or dismisses it, rather than closing automatically. #[builder(into)] require_interaction: Option, - // /// A boolean value specifying whether the user should be notified after a new notification replaces an old one. - // /// The default is `false`, which means they won't be notified. If `true`, then `tag` also must be set. - // #[builder(into)] - // renotify: Option, + /// A boolean value specifying whether the user should be notified after a new notification replaces an old one. + /// The default is `false`, which means they won't be notified. If `true`, then `tag` also must be set. + #[builder(into)] + renotify: Option, } #[cfg(not(feature = "ssr"))] @@ -413,9 +414,9 @@ impl ShowOptions { options.tag(tag); } - // if let Some(renotify) = &self.renotify { - // options.renotify(renotify); - // } + if let Some(renotify) = self.renotify { + options.renotify(renotify); + } } }