Notifications UI: limit entries, improve grouping (#23241)
Co-authored-by: Michael Geers <michael@geers.tv>
This commit is contained in:
parent
e00017d55b
commit
cb33486843
1 changed files with 13 additions and 10 deletions
|
|
@ -33,18 +33,21 @@ const app = createApp(
|
|||
if (this.offline) return;
|
||||
if (!msg.level) msg.level = "error";
|
||||
const now = new Date();
|
||||
const latestMsg = this.notifications[0];
|
||||
if (latestMsg && latestMsg.message === msg.message && latestMsg.lp === msg.lp) {
|
||||
latestMsg.count++;
|
||||
latestMsg.time = now;
|
||||
const existingMsg = this.notifications.find(
|
||||
(n) => n.message === msg.message && n.lp === msg.lp
|
||||
);
|
||||
if (existingMsg) {
|
||||
existingMsg.count++;
|
||||
existingMsg.time = now;
|
||||
// move to front
|
||||
this.notifications = [
|
||||
existingMsg,
|
||||
...this.notifications.filter((n) => n !== existingMsg),
|
||||
];
|
||||
} else {
|
||||
this.notifications = [
|
||||
{
|
||||
...msg,
|
||||
count: 1,
|
||||
time: now,
|
||||
},
|
||||
...this.notifications,
|
||||
{ ...msg, count: 1, time: now },
|
||||
...this.notifications.slice(0, 14), // keep only last 15
|
||||
];
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue