diff --git a/src_ts/components/app-shell/app-shell.ts b/src_ts/components/app-shell/app-shell.ts index b50abea7..934ae97c 100644 --- a/src_ts/components/app-shell/app-shell.ts +++ b/src_ts/components/app-shell/app-shell.ts @@ -39,6 +39,7 @@ import './footer/page-footer.js'; import './app-theme.js'; import {ToastNotificationHelper} from '../common/toast-notifications/toast-notification-helper'; +import '../common/etools-notifications/etools-notifications'; import user from '../../redux/reducers/user'; import commonData, {CommonDataState} from '../../redux/reducers/common-data'; import {SMALL_MENU_ACTIVE_LOCALSTORAGE_KEY} from '../../config/config'; @@ -185,6 +186,9 @@ export class AppShell extends connect(store)(LoadingMixin(LitElement)) { this.appToastsNotificationsHelper = new ToastNotificationHelper(); this.appToastsNotificationsHelper.addToastNotificationListeners(); + const etoolsNotifications = document.createElement('etools-notifications'); + document.querySelector('body')!.appendChild(etoolsNotifications); + const menuTypeStoredVal: string | null = localStorage.getItem(SMALL_MENU_ACTIVE_LOCALSTORAGE_KEY); if (!menuTypeStoredVal) { this.smallMenu = false; diff --git a/src_ts/components/common/etools-notifications/etools-notifications.ts b/src_ts/components/common/etools-notifications/etools-notifications.ts new file mode 100644 index 00000000..19aca018 --- /dev/null +++ b/src_ts/components/common/etools-notifications/etools-notifications.ts @@ -0,0 +1,124 @@ +import {LitElement, html, customElement, property} from 'lit-element'; +import {AnyObject} from '@unicef-polymer/etools-types'; + +/** + * @LitElement + * @customElement + */ +@customElement('etools-notifications') +export class EtoolsNotifications extends LitElement { + public render() { + // main template + // language=HTML + return html` + + + ${this.notifications.length + ? html`` + : html``} + `; + } + + @property({type: Array}) + notifications: AnyObject[] = []; + + @property({type: Boolean}) + showNotification = false; + + connectedCallback() { + super.connectedCallback(); + + this._updateNotifications = this._updateNotifications.bind(this); + document.body.addEventListener('show-notification', this._updateNotifications as any); + + setTimeout(() => { + this.getDummyData(); + }, 5000); + } + + _updateNotifications(e: CustomEvent) { + this.renderNotifications(this.notifications.concat(e.detail.notifications || [])); + } + + removeNotification(id: string) { + this.notifications = this.notifications.filter((item) => item.id !== id); + } + + getNotificationHtml(item: AnyObject, showItem: boolean) { + return html` +
  • + ${item.message} + +
  • + `; + } + + renderNotifications(items: AnyObject[]) { + this.showNotification = false; + // depemds how we want to display new added notifications + + // this.notifications = []; + // setTimeout(() => { + this.notifications = items; + setTimeout(() => { + this.showNotification = true; + }, 100); + // }, 100); + } + + getDummyData() { + this.showNotification = false; + const messages = [ + // eslint-disable-next-line max-len + 'Maecenas magna lectus, vestibulum ut nisl iaculis, mollis semper diam. Curabitur erat enim, finibus vel volutpat quis, consectetur at ante.', + 'Maecenas rutrum libero at erat sagittis aliquet. Duis tempus lacinia dui vitae consequat.' + ]; + const dummyData = []; + for (let i = 0; i < 6; i++) { + dummyData.push({id: i, message: messages[i % 2]}); + } + this.renderNotifications(dummyData); + } +}