summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/whats_new/utils/notification.js
blob: 52ca8058d1cebe036cf4897b81b63e5a2d546993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export const getStorageKey = (appEl) => appEl.getAttribute('data-storage-key');

export const setNotification = (appEl) => {
  const storageKey = getStorageKey(appEl);
  const notificationEl = document.querySelector('.header-help');
  let notificationCountEl = notificationEl.querySelector('.js-whats-new-notification-count');

  if (JSON.parse(localStorage.getItem(storageKey)) === false) {
    notificationEl.classList.remove('with-notifications');
    if (notificationCountEl) {
      notificationCountEl.parentElement.removeChild(notificationCountEl);
      notificationCountEl = null;
    }
  } else {
    notificationEl.classList.add('with-notifications');
  }
};