From 0b6903fcccb5ca8fca17b7154e52b5e79fddd919 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 31 Jul 2024 21:47:38 -0400 Subject: [PATCH 1/4] 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); + } } } From 88af0e735dfdd5ae1e82ad8878dc697e0aed91fd Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 31 Jul 2024 22:18:58 -0400 Subject: [PATCH 2/4] Feat: Add `silent` field to `UseWebNotificationOptions` and `ShowOptions` Introduced the `silent` field to the `UseWebNotificationOptions` and `ShowOptions` structures, allowing notifications to be displayed in silent. --- src/use_web_notification.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 8870a89..986fcc8 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -229,7 +229,6 @@ impl From for web_sys::NotificationDirection { /// /// The following implementations are missing: /// - `vibrate` -/// - `silent` /// - `image` #[derive(DefaultBuilder, Clone)] #[cfg_attr(feature = "ssr", allow(dead_code))] @@ -273,6 +272,11 @@ pub struct UseWebNotificationOptions { #[builder(into)] renotify: bool, + /// A boolean value specifying whether the notification should be silent, regardless of the device settings. + /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. + #[builder(into)] + silent: Option, + /// Called when the user clicks on displayed `Notification`. on_click: Rc, @@ -298,6 +302,7 @@ impl Default for UseWebNotificationOptions { icon: None, require_interaction: false, renotify: false, + silent: None, on_click: Rc::new(|_| {}), on_close: Rc::new(|_| {}), on_error: Rc::new(|_| {}), @@ -313,7 +318,8 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options .dir(options.direction.into()) .require_interaction(options.require_interaction) - .renotify(options.renotify); + .renotify(options.renotify) + .silent(options.silent); if let Some(body) = &options.body { web_sys_options.body(body); @@ -340,8 +346,7 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { /// See [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/notification) for more info. /// /// The following implementations are missing: -/// - `vibrate` -/// - `silent` +/// - `vibrate` /// - `image` #[derive(DefaultBuilder, Default)] #[cfg_attr(feature = "ssr", allow(dead_code))] @@ -381,10 +386,16 @@ 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 notification should be silent, regardless of the device settings. + /// The default is `false`, which means the notification is not silent. If `true`, then the notification will be silent. + #[builder(into)] + silent: Option, } #[cfg(not(feature = "ssr"))] @@ -417,6 +428,10 @@ impl ShowOptions { if let Some(renotify) = self.renotify { options.renotify(renotify); } + + if let Some(silent) = self.silent { + options.silent(Some(silent)); + } } } From f37f28cfff3f6de50e36d72b4fcc9682b2ed3e90 Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Wed, 31 Jul 2024 23:07:18 -0400 Subject: [PATCH 3/4] Feat: Add `image` field to `UseWebNotificationOptions` and `ShowOptions` Added the `image` field to the `UseWebNotificationOptions` and `ShowOptions` structures. This field allows specifying an image URL to be displayed in the notification. --- src/use_web_notification.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index 986fcc8..a919052 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -229,7 +229,6 @@ impl From for web_sys::NotificationDirection { /// /// The following implementations are missing: /// - `vibrate` -/// - `image` #[derive(DefaultBuilder, Clone)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct UseWebNotificationOptions { @@ -263,6 +262,11 @@ pub struct UseWebNotificationOptions { #[builder(into)] icon: Option, + /// The URL of the image to be displayed as part of the notification as specified + /// in the constructor's options parameter. + #[builder(into)] + image: Option, + /// A boolean value indicating that a notification should remain active until the /// user clicks or dismisses it, rather than closing automatically. require_interaction: bool, @@ -300,6 +304,7 @@ impl Default for UseWebNotificationOptions { language: None, tag: None, icon: None, + image: None, require_interaction: false, renotify: false, silent: None, @@ -329,6 +334,10 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { web_sys_options.icon(icon); } + if let Some(image) = &options.image { + web_sys_options.image(image); + } + if let Some(language) = &options.language { web_sys_options.lang(language); } @@ -347,7 +356,6 @@ impl From<&UseWebNotificationOptions> for web_sys::NotificationOptions { /// /// The following implementations are missing: /// - `vibrate` -/// - `image` #[derive(DefaultBuilder, Default)] #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct ShowOptions { @@ -382,6 +390,11 @@ pub struct ShowOptions { #[builder(into)] icon: Option, + /// The URL of the image to be displayed as part of the notification as specified + /// in the constructor's options parameter. + #[builder(into)] + image: Option, + /// A boolean value indicating that a notification should remain active until the /// user clicks or dismisses it, rather than closing automatically. #[builder(into)] @@ -417,6 +430,10 @@ impl ShowOptions { options.icon(icon); } + if let Some(image) = &self.image { + options.image(image); + } + if let Some(language) = &self.language { options.lang(language); } From 2a8a2b81e4adf177c060034dfa2b52464b8ae7ff Mon Sep 17 00:00:00 2001 From: Hector Candelaria Date: Thu, 1 Aug 2024 01:15:37 -0400 Subject: [PATCH 4/4] Doc: fixed typo --- src/use_web_notification.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/use_web_notification.rs b/src/use_web_notification.rs index a919052..01098a4 100644 --- a/src/use_web_notification.rs +++ b/src/use_web_notification.rs @@ -28,7 +28,7 @@ use std::rc::Rc; /// UseWebNotificationOptions::default() /// .direction(NotificationDirection::Auto) /// .language("en") -/// .renotity(true) +/// .renotify(true) /// .tag("test"), /// ); ///