From 70ca6ed0bdd6c6e1aaa83cb783c1c4bd32b3c743 Mon Sep 17 00:00:00 2001 From: Vivek Nigam Date: Tue, 14 Jul 2020 00:58:07 +0530 Subject: [PATCH] Towards #18: Sending Alert Notifications --- .../NativeNotifications/AlertNotification.js | 8 ++++++++ .../Notifications/Reducers/NotificationReducer.js | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 src/components/Notifications/NativeNotifications/AlertNotification.js diff --git a/src/components/Notifications/NativeNotifications/AlertNotification.js b/src/components/Notifications/NativeNotifications/AlertNotification.js new file mode 100644 index 0000000..240e00d --- /dev/null +++ b/src/components/Notifications/NativeNotifications/AlertNotification.js @@ -0,0 +1,8 @@ +export function doNotify(message) { + Notification.requestPermission().then(() => { + new window.Notification('Rucio Notifier', { + 'body': message, + 'icon': 'electorn-logo=2.png' + }); + }); +} \ No newline at end of file diff --git a/src/components/Notifications/Reducers/NotificationReducer.js b/src/components/Notifications/Reducers/NotificationReducer.js index 04f6f0d..06e7ce7 100644 --- a/src/components/Notifications/Reducers/NotificationReducer.js +++ b/src/components/Notifications/Reducers/NotificationReducer.js @@ -1,3 +1,5 @@ +import { doNotify } from "../NativeNotifications/AlertNotification"; + const notification = JSON.parse(localStorage.getItem('notifications')) function notificationReducer(state = notification, action) { @@ -14,6 +16,7 @@ function notificationReducer(state = notification, action) { read: false, }); console.log(newNotification); + doNotify(action.primary) localStorage.setItem('notifications', JSON.stringify(newNotification)) return newNotification;