From d9a954ca91a1b5803e3df5f8b33118667eeae382 Mon Sep 17 00:00:00 2001 From: Matt <927830+mattmattmatt@users.noreply.github.com> Date: Mon, 12 Oct 2020 02:25:04 -0600 Subject: [PATCH] Close notification drawer after dismissing last notification (#7229) * Close notification drawer after dismissing last This change adds a listener to any changes of the notifications property once the drawer opens. After the last notification is dismissed, the notification drawer closes automatically, and the listener is removed. * Use observer instead event for notification change Using the observer pattern instead subscribing to change events for notification changes simplifies the implementation noticeably. --- src/dialogs/notifications/notification-drawer.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dialogs/notifications/notification-drawer.js b/src/dialogs/notifications/notification-drawer.js index 927af2f3a9..3b7c5c54da 100644 --- a/src/dialogs/notifications/notification-drawer.js +++ b/src/dialogs/notifications/notification-drawer.js @@ -88,6 +88,7 @@ export class HuiNotificationDrawer extends EventsMixin( notifications: { type: Array, computed: "_computeNotifications(open, hass, _notificationsBackend)", + observer: "_notificationsChanged", }, _notificationsBackend: { type: Array, @@ -130,6 +131,17 @@ export class HuiNotificationDrawer extends EventsMixin( } } + _notificationsChanged(newNotifications, oldNotifications) { + // automatically close drawer when last notification has been dismissed + if ( + this.open && + oldNotifications.length > 0 && + !newNotifications.length === 0 + ) { + this.open = false; + } + } + _computeNotifications(open, hass, notificationsBackend) { if (!open) { return [];