notifs: single-pass derived properties in NotifGroup

This commit is contained in:
2 * r + 2 * t 2026-03-12 22:21:05 +11:00
parent 51579474c5
commit 314301157e
2 changed files with 54 additions and 7 deletions

View file

@ -17,9 +17,30 @@ StyledRect {
required property string modelData
readonly property list<var> notifs: Notifs.list.filter(notif => notif.appName === modelData)
readonly property string image: notifs.find(n => n.image.length > 0)?.image ?? ""
readonly property string appIcon: notifs.find(n => n.appIcon.length > 0)?.appIcon ?? ""
readonly property string urgency: notifs.some(n => n.urgency === NotificationUrgency.Critical) ? "critical" : notifs.some(n => n.urgency === NotificationUrgency.Normal) ? "normal" : "low"
readonly property var props: {
let img = "";
let icon = "";
let hasCritical = false;
let hasNormal = false;
for (const n of notifs) {
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 {
img,
icon,
urgency: hasCritical ? "critical" : hasNormal ? "normal" : "low"
};
}
readonly property string image: props.img
readonly property string appIcon: props.icon
readonly property string urgency: props.urgency
property bool expanded

View file

@ -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);