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:
@@ -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),
|
||||
],
|
||||
});
|
||||
}));
|
||||
});
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user