summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ci/runner/local_storage_alert/show_alert_from_local_storage.js
blob: bad3ca6024ea6136d643d081e92fbc4d6d4d7abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import AccessorUtilities from '~/lib/utils/accessor';
import { LOCAL_STORAGE_ALERT_KEY } from './constants';

export const showAlertFromLocalStorage = async () => {
  if (AccessorUtilities.canUseLocalStorage()) {
    const alertOptions = localStorage.getItem(LOCAL_STORAGE_ALERT_KEY);

    if (alertOptions) {
      try {
        const { createAlert } = await import('~/alert');
        createAlert(JSON.parse(alertOptions));
      } catch {
        // ignore when the alert data cannot be parsed
      }
    }
    localStorage.removeItem(LOCAL_STORAGE_ALERT_KEY);
  }
};