Added filters for notifications and system tray items. (#234)

* Added filters for notifications and systray. closes #233

* Add links to documentation.
This commit is contained in:
Jas Singh
2024-09-08 02:01:13 -07:00
committed by GitHub
parent bd573ec4e7
commit 4f91bb8b8f
22 changed files with 630 additions and 174 deletions

View File

@@ -8,8 +8,9 @@ import { Body } from "./body/index.js";
import { CloseButton } from "./close/index.js";
import options from "options.js";
import { Variable } from "types/variable.js";
import { filterNotifications } from "lib/shared/notifications.js";
const { displayedTotal } = options.notifications;
const { displayedTotal, ignore } = options.notifications;
const NotificationCard = (notifs: Notifications, curPage: Variable<number>) => {
return Widget.Scrollable({
@@ -21,46 +22,60 @@ const NotificationCard = (notifs: Notifications, curPage: Variable<number>) => {
spacing: 0,
vertical: true,
setup: (self) => {
Utils.merge([notifs.bind("notifications"), curPage.bind("value"), displayedTotal.bind("value")], (notifications, currentPage, dispTotal) => {
const sortedNotifications = notifications.sort(
(a, b) => b.time - a.time,
);
Utils.merge(
[
notifs.bind("notifications"),
curPage.bind("value"),
displayedTotal.bind("value"),
ignore.bind("value")
],
(
notifications,
currentPage,
dispTotal,
ignoredNotifs
) => {
const filteredNotifications = filterNotifications(notifications, ignoredNotifs);
if (notifications.length <= 0) {
return (self.children = [Placeholder(notifs)]);
}
const sortedNotifications = filteredNotifications.sort(
(a, b) => b.time - a.time,
);
const pageStart = (currentPage - 1) * dispTotal;
const pageEnd = currentPage * dispTotal;
return (self.children = sortedNotifications.slice(pageStart, pageEnd).map((notif: Notification) => {
return Widget.Box({
class_name: "notification-card-content-container",
children: [
Widget.Box({
class_name: "notification-card menu",
vpack: "start",
hexpand: true,
vexpand: false,
children: [
Image(notif),
Widget.Box({
vpack: "center",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : " menu"}`,
children: [
Header(notif),
Body(notif),
Actions(notif, notifs),
],
}),
],
}),
CloseButton(notif, notifs),
],
});
}));
});
if (filteredNotifications.length <= 0) {
return (self.children = [Placeholder(notifs)]);
}
const pageStart = (currentPage - 1) * dispTotal;
const pageEnd = currentPage * dispTotal;
return (self.children = sortedNotifications.slice(pageStart, pageEnd).map((notif: Notification) => {
return Widget.Box({
class_name: "notification-card-content-container",
children: [
Widget.Box({
class_name: "notification-card menu",
vpack: "start",
hexpand: true,
vexpand: false,
children: [
Image(notif),
Widget.Box({
vpack: "center",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : " menu"}`,
children: [
Header(notif),
Body(notif),
Actions(notif, notifs),
],
}),
],
}),
CloseButton(notif, notifs),
],
});
}));
});
},
})
});