HyprPanel now handles notification removal itself. (#242)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { closeNotifications } from "globals/notification";
|
||||
import { Notifications } from "types/service/notifications";
|
||||
|
||||
const Controls = (notifs: Notifications) => {
|
||||
@@ -40,11 +41,21 @@ const Controls = (notifs: Notifications) => {
|
||||
class_name: "menu-separator notification-controls",
|
||||
}),
|
||||
Widget.Button({
|
||||
class_name: "clear-notifications-button",
|
||||
className: "clear-notifications-button",
|
||||
tooltip_text: "Clear Notifications",
|
||||
on_primary_click: () => notifs.clear(),
|
||||
on_primary_click: () => {
|
||||
if (removingNotifications.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
closeNotifications(notifs.notifications);
|
||||
},
|
||||
child: Widget.Label({
|
||||
class_name: "clear-notifications-label txt-icon",
|
||||
class_name: removingNotifications.bind("value").as((removing: boolean) => {
|
||||
return removing
|
||||
? "clear-notifications-label txt-icon removing"
|
||||
: "clear-notifications-label txt-icon";
|
||||
}),
|
||||
label: "",
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Notification } from "types/service/notifications.js";
|
||||
import DropdownMenu from "../DropdownMenu.js";
|
||||
const notifs = await Service.import("notifications");
|
||||
import { Controls } from "./controls/index.js";
|
||||
@@ -7,18 +8,27 @@ import { NotificationPager } from "./pager/index.js";
|
||||
import options from "options";
|
||||
|
||||
const { displayedTotal } = options.notifications;
|
||||
const { show: showPager } = options.theme.bar.menus.menu.notifications.pager;
|
||||
|
||||
export default () => {
|
||||
const curPage = Variable(1);
|
||||
|
||||
Utils.merge([curPage.bind("value"), displayedTotal.bind("value"), notifs.bind("notifications")], (currentPage, dispTotal, notifications) => {
|
||||
// If the page doesn't have enough notifications to display, go back
|
||||
// to the previous page.
|
||||
if (notifications.length <= (currentPage - 1) * dispTotal) {
|
||||
curPage.value = currentPage <= 1 ? 1 : currentPage - 1;
|
||||
}
|
||||
});
|
||||
Utils.merge(
|
||||
[
|
||||
curPage.bind("value"),
|
||||
displayedTotal.bind("value"),
|
||||
notifs.bind("notifications"),
|
||||
],
|
||||
(
|
||||
currentPage: number,
|
||||
dispTotal: number,
|
||||
notifications: Notification[],
|
||||
) => {
|
||||
// If the page doesn't have enough notifications to display, go back
|
||||
// to the previous page.
|
||||
if (notifications.length <= (currentPage - 1) * dispTotal) {
|
||||
curPage.value = currentPage <= 1 ? 1 : currentPage - 1;
|
||||
}
|
||||
});
|
||||
|
||||
return DropdownMenu({
|
||||
name: "notificationsmenu",
|
||||
@@ -34,13 +44,7 @@ export default () => {
|
||||
vertical: true,
|
||||
hexpand: false,
|
||||
vexpand: false,
|
||||
children: showPager.bind("value").as(shPgr => {
|
||||
if (shPgr) {
|
||||
return [Controls(notifs), NotificationCard(notifs, curPage), NotificationPager(curPage)];
|
||||
}
|
||||
return [Controls(notifs), NotificationCard(notifs, curPage)]
|
||||
|
||||
})
|
||||
children: [Controls(notifs), NotificationCard(notifs, curPage), NotificationPager(curPage)]
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
||||
@@ -1,74 +1,91 @@
|
||||
const notifs = await Service.import("notifications");
|
||||
|
||||
import options from "options";
|
||||
import { Notification } from "types/service/notifications";
|
||||
import { Variable } from "types/variable";
|
||||
|
||||
const { displayedTotal } = options.notifications;
|
||||
const { show: showPager } = options.theme.bar.menus.menu.notifications.pager;
|
||||
|
||||
export const NotificationPager = (curPage: Variable<number>) => {
|
||||
return Widget.Box({
|
||||
class_name: "notification-menu-pager",
|
||||
hexpand: true,
|
||||
vexpand: false,
|
||||
children: Utils.merge([curPage.bind("value"), displayedTotal.bind("value"), notifs.bind("notifications")], (currentPage, dispTotal, _) => {
|
||||
return [
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "start",
|
||||
class_name: `pager-button left ${currentPage <= 1 ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
curPage.value = 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
children: Utils.merge(
|
||||
[
|
||||
curPage.bind("value"),
|
||||
displayedTotal.bind("value"),
|
||||
notifs.bind("notifications"),
|
||||
showPager.bind("value")
|
||||
],
|
||||
(
|
||||
currentPage: number,
|
||||
dispTotal: number,
|
||||
_: Notification[],
|
||||
showPgr: boolean
|
||||
) => {
|
||||
if (showPgr === false) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "start",
|
||||
class_name: `pager-button left ${currentPage <= 1 ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
curPage.value = 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "start",
|
||||
class_name: `pager-button left ${currentPage <= 1 ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
curPage.value = currentPage <= 1 ? 1 : currentPage - 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "start",
|
||||
class_name: `pager-button left ${currentPage <= 1 ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
curPage.value = currentPage <= 1 ? 1 : currentPage - 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
Widget.Label({
|
||||
hexpand: true,
|
||||
hpack: "center",
|
||||
class_name: "pager-label",
|
||||
label: `${currentPage} / ${Math.ceil(notifs.notifications.length / dispTotal) || 1}`
|
||||
}),
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "end",
|
||||
class_name: `pager-button right ${currentPage >= Math.ceil(notifs.notifications.length / dispTotal) ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
const maxPage = Math.ceil(notifs.notifications.length / displayedTotal.value);
|
||||
curPage.value = currentPage >= maxPage ? currentPage : currentPage + 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
Widget.Label({
|
||||
hexpand: true,
|
||||
hpack: "center",
|
||||
class_name: "pager-label",
|
||||
label: `${currentPage} / ${Math.ceil(notifs.notifications.length / dispTotal) || 1}`
|
||||
}),
|
||||
}),
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "end",
|
||||
class_name: `pager-button right ${currentPage >= Math.ceil(notifs.notifications.length / dispTotal) ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
const maxPage = Math.ceil(notifs.notifications.length / displayedTotal.value);
|
||||
curPage.value = maxPage;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "end",
|
||||
class_name: `pager-button right ${currentPage >= Math.ceil(notifs.notifications.length / dispTotal) ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
const maxPage = Math.ceil(notifs.notifications.length / displayedTotal.value);
|
||||
curPage.value = currentPage >= maxPage ? currentPage : currentPage + 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
]
|
||||
})
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "end",
|
||||
class_name: `pager-button right ${currentPage >= Math.ceil(notifs.notifications.length / dispTotal) ? "disabled" : ""}`,
|
||||
onPrimaryClick: () => {
|
||||
const maxPage = Math.ceil(notifs.notifications.length / displayedTotal.value);
|
||||
curPage.value = maxPage;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
}),
|
||||
}),
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user