2
0

notifications.js 847 B

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