diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:21:05 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:21:05 +1100 |
| commit | 314301157e6f2d9859cc51272b5f8a4f70cc05dd (patch) | |
| tree | a5b1c815f3e37593a9d7a0f9331187c5a37ee0ed /modules/sidebar | |
| parent | workspaces: replace reduce with for loop for occupied map (diff) | |
| download | caelestia-shell-314301157e6f2d9859cc51272b5f8a4f70cc05dd.tar.gz caelestia-shell-314301157e6f2d9859cc51272b5f8a4f70cc05dd.tar.bz2 caelestia-shell-314301157e6f2d9859cc51272b5f8a4f70cc05dd.zip | |
notifs: single-pass derived properties in NotifGroup
Diffstat (limited to 'modules/sidebar')
| -rw-r--r-- | modules/sidebar/NotifGroup.qml | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/modules/sidebar/NotifGroup.qml b/modules/sidebar/NotifGroup.qml index 16aac33..4e338da 100644 --- a/modules/sidebar/NotifGroup.qml +++ b/modules/sidebar/NotifGroup.qml @@ -19,10 +19,36 @@ StyledRect { required property var visibilities readonly property list<var> notifs: Notifs.list.filter(n => n.appName === modelData) - readonly property int notifCount: notifs.reduce((acc, n) => n.closed ? acc : acc + 1, 0) - readonly property string image: notifs.find(n => !n.closed && n.image.length > 0)?.image ?? "" - readonly property string appIcon: notifs.find(n => !n.closed && n.appIcon.length > 0)?.appIcon ?? "" - readonly property int urgency: notifs.some(n => !n.closed && n.urgency === NotificationUrgency.Critical) ? NotificationUrgency.Critical : notifs.some(n => n.urgency === NotificationUrgency.Normal) ? NotificationUrgency.Normal : NotificationUrgency.Low + readonly property var groupProps: { + let count = 0; + let img = ""; + let icon = ""; + let hasCritical = false; + let hasNormal = false; + for (const n of notifs) { + if (!n.closed) { + count++; + if (!img && n.image.length > 0) + img = n.image; + if (!icon && n.appIcon.length > 0) + icon = n.appIcon; + if (n.urgency === NotificationUrgency.Critical) + hasCritical = true; + else if (n.urgency === NotificationUrgency.Normal) + hasNormal = true; + } + } + return { + count, + img, + icon, + urgency: hasCritical ? NotificationUrgency.Critical : hasNormal ? NotificationUrgency.Normal : NotificationUrgency.Low + }; + } + readonly property int notifCount: groupProps.count + readonly property string image: groupProps.img + readonly property string appIcon: groupProps.icon + readonly property int urgency: groupProps.urgency readonly property int nonAnimHeight: { const headerHeight = header.implicitHeight + (root.expanded ? Math.round(Appearance.spacing.small / 2) : 0); |