mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
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:
parent
c219f64322
commit
d9a954ca91
@ -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 [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user