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.
This commit is contained in:
Matt 2020-10-12 02:25:04 -06:00 committed by GitHub
parent c219f64322
commit d9a954ca91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 [];