notifications.js 790 B

1234567891011121314151617181920212223242526272829303132
  1. // this hides the notifications drawer if anyone clicks off of the panel
  2. Template.body.events({
  3. click(event) {
  4. if (
  5. !$(event.target).is('#notifications *') &&
  6. Session.get('showNotificationsDrawer')
  7. ) {
  8. toggleNotificationsDrawer();
  9. }
  10. },
  11. });
  12. Template.notifications.helpers({
  13. unreadNotifications() {
  14. const notifications = Users.findOne(Meteor.userId()).notifications();
  15. const unreadNotifications = _.filter(notifications, v => !v.read);
  16. return unreadNotifications.length;
  17. },
  18. });
  19. Template.notifications.events({
  20. 'click .notifications-drawer-toggle'() {
  21. toggleNotificationsDrawer();
  22. },
  23. });
  24. export function toggleNotificationsDrawer() {
  25. Session.set(
  26. 'showNotificationsDrawer',
  27. !Session.get('showNotificationsDrawer'),
  28. );
  29. }