Skip to content

Commit

Permalink
WEBUI-425: limit the number of notifications displayed at every singl…
Browse files Browse the repository at this point in the history
…e time
  • Loading branch information
richardsd committed Aug 31, 2021
1 parent e216bb5 commit f0cdafa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions elements/nuxeo-app.js
Expand Up @@ -91,7 +91,7 @@ window.nuxeo.importBlacklist = window.nuxeo.importBlacklist || [
'Domain',
'Root',
];
const MAX_TOASTS = 2; // max number of toasts that can be displayed simultaneously besides the default one
const MAX_TOASTS = 3; // max number of toasts that can be displayed simultaneously besides the default one

setPassiveTouchGestures(true);

Expand Down Expand Up @@ -1379,6 +1379,8 @@ Polymer({
toast.mdcRoot.querySelector('.mdc-snackbar__label').style.webkitFontSmoothing = 'auto';
toast.mdcRoot.querySelector('.mdc-snackbar__surface').style.width = '344px';
});
// set the initial state of the snackbar
toast.__state = {};

// listen to the closed event to track dismiss and custom action
toast.addEventListener('MDCSnackbar:closed', (e) => {
Expand Down Expand Up @@ -1417,17 +1419,17 @@ Polymer({
},

_notify(e) {
const { commandId } = e.detail;
const toast = this._getToastFor(commandId, e.detail);
const { abort, close, dismissible, duration, message } = e.detail;

// if the size of the panel is higher than the max value, we need to dismiss the oldest
const snackbars = this.$.snackbarPanel.querySelectorAll('mwc-snackbar:not(#toast)');
if (snackbars.length > MAX_TOASTS) {
const snackbar = snackbars[0];
snackbar.close('dismiss');
}

const { commandId } = e.detail;
const toast = this._getToastFor(commandId, e.detail);
const { abort, close, dismissible, duration, message } = e.detail;

if (close) {
toast.close();
}
Expand Down

0 comments on commit f0cdafa

Please sign in to comment.