From 9819c9f801128d07374b0703b482bdb83a672297 Mon Sep 17 00:00:00 2001 From: Jonathan Baird Date: Fri, 27 Mar 2020 11:35:03 -0600 Subject: add a notification drawer like trello --- .../notifications/notificationsDrawer.js | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 client/components/notifications/notificationsDrawer.js (limited to 'client/components/notifications/notificationsDrawer.js') diff --git a/client/components/notifications/notificationsDrawer.js b/client/components/notifications/notificationsDrawer.js new file mode 100644 index 00000000..98d4750d --- /dev/null +++ b/client/components/notifications/notificationsDrawer.js @@ -0,0 +1,38 @@ +import { toggleNotificationsDrawer } from './notifications.js'; + +Template.notificationsDrawer.onCreated(function() { + Meteor.subscribe('notificationActivities'); + Meteor.subscribe('notificationCards'); + Meteor.subscribe('notificationUsers'); + Meteor.subscribe('notificationsAttachments'); + Meteor.subscribe('notificationChecklistItems'); + Meteor.subscribe('notificationChecklists'); + Meteor.subscribe('notificationComments'); + Meteor.subscribe('notificationLists'); + Meteor.subscribe('notificationSwimlanes'); +}); + +Template.notificationsDrawer.helpers({ + transformedProfile() { + return Users.findOne(Meteor.userId()); + }, +}); + +Template.notificationsDrawer.events({ + 'click .all-read'() { + const notifications = Meteor.user().profile.notifications; + for (const index in notifications) { + if (notifications.hasOwnProperty(index) && !notifications[index].read) { + const update = {}; + update[`profile.notifications.${index}.read`] = Date.now(); + Users.update(Meteor.userId(), { $set: update }); + } + } + }, + 'click .close'() { + toggleNotificationsDrawer(); + }, + 'click .toggle-read'() { + Session.set('showReadNotifications', !Session.get('showReadNotifications')); + }, +}); -- cgit v1.2.3-1-g7c22 From a182dde11ff4f1ab8cd01a04e1e26affda5d8a3b Mon Sep 17 00:00:00 2001 From: Jonathan Baird Date: Wed, 8 Apr 2020 13:14:29 -0600 Subject: add a "remove all read" button to notification menu --- client/components/notifications/notificationsDrawer.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'client/components/notifications/notificationsDrawer.js') diff --git a/client/components/notifications/notificationsDrawer.js b/client/components/notifications/notificationsDrawer.js index 98d4750d..76abeea7 100644 --- a/client/components/notifications/notificationsDrawer.js +++ b/client/components/notifications/notificationsDrawer.js @@ -16,6 +16,13 @@ Template.notificationsDrawer.helpers({ transformedProfile() { return Users.findOne(Meteor.userId()); }, + readNotifications() { + const readNotifications = _.filter( + Meteor.user().profile.notifications, + v => !!v.read, + ); + return readNotifications.length; + }, }); Template.notificationsDrawer.events({ @@ -35,4 +42,12 @@ Template.notificationsDrawer.events({ 'click .toggle-read'() { Session.set('showReadNotifications', !Session.get('showReadNotifications')); }, + 'click .remove-read'() { + const user = Meteor.user(); + for (const notification of user.profile.notifications) { + if (notification.read) { + user.removeNotification(notification.activity); + } + } + }, }); -- cgit v1.2.3-1-g7c22