Implemented strict linting standards and prettier formatting config. (#248)
* Implemented strict linting standards and prettier formatting config. * More linter fixes and type updates. * More linter updates and type fixes * Remove noisy comments * Linter and type updates * Linter, formatting and type updates. * Linter updates * Type updates * Type updates * fixed all linter errors * Fixed all linting, formatting and type issues. * Resolve merge conflicts.
This commit is contained in:
@@ -1,33 +1,34 @@
|
||||
import { closeNotifications } from "globals/notification";
|
||||
import { Notifications } from "types/service/notifications";
|
||||
import { closeNotifications } from 'globals/notification';
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { Notifications } from 'types/service/notifications';
|
||||
|
||||
const Controls = (notifs: Notifications) => {
|
||||
const Controls = (notifs: Notifications): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: "notification-menu-controls",
|
||||
class_name: 'notification-menu-controls',
|
||||
expand: false,
|
||||
vertical: false,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "menu-label-container notifications",
|
||||
hpack: "start",
|
||||
vpack: "center",
|
||||
class_name: 'menu-label-container notifications',
|
||||
hpack: 'start',
|
||||
vpack: 'center',
|
||||
expand: true,
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "menu-label notifications",
|
||||
label: "Notifications",
|
||||
class_name: 'menu-label notifications',
|
||||
label: 'Notifications',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
hpack: "end",
|
||||
vpack: "center",
|
||||
hpack: 'end',
|
||||
vpack: 'center',
|
||||
expand: false,
|
||||
children: [
|
||||
Widget.Switch({
|
||||
class_name: "menu-switch notifications",
|
||||
vpack: "center",
|
||||
active: notifs.bind("dnd").as((dnd: boolean) => !dnd),
|
||||
class_name: 'menu-switch notifications',
|
||||
vpack: 'center',
|
||||
active: notifs.bind('dnd').as((dnd: boolean) => !dnd),
|
||||
on_activate: ({ active }) => {
|
||||
notifs.dnd = !active;
|
||||
},
|
||||
@@ -35,14 +36,14 @@ const Controls = (notifs: Notifications) => {
|
||||
Widget.Box({
|
||||
children: [
|
||||
Widget.Separator({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
vexpand: true,
|
||||
vertical: true,
|
||||
class_name: "menu-separator notification-controls",
|
||||
class_name: 'menu-separator notification-controls',
|
||||
}),
|
||||
Widget.Button({
|
||||
className: "clear-notifications-button",
|
||||
tooltip_text: "Clear Notifications",
|
||||
className: 'clear-notifications-button',
|
||||
tooltip_text: 'Clear Notifications',
|
||||
on_primary_click: () => {
|
||||
if (removingNotifications.value) {
|
||||
return;
|
||||
@@ -51,12 +52,12 @@ const Controls = (notifs: Notifications) => {
|
||||
closeNotifications(notifs.notifications);
|
||||
},
|
||||
child: Widget.Label({
|
||||
class_name: removingNotifications.bind("value").as((removing: boolean) => {
|
||||
class_name: removingNotifications.bind('value').as((removing: boolean) => {
|
||||
return removing
|
||||
? "clear-notifications-label txt-icon removing"
|
||||
: "clear-notifications-label txt-icon";
|
||||
? 'clear-notifications-label txt-icon removing'
|
||||
: 'clear-notifications-label txt-icon';
|
||||
}),
|
||||
label: "",
|
||||
label: '',
|
||||
}),
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -1,50 +1,45 @@
|
||||
import { Notification } from "types/service/notifications.js";
|
||||
import DropdownMenu from "../DropdownMenu.js";
|
||||
const notifs = await Service.import("notifications");
|
||||
import { Controls } from "./controls/index.js";
|
||||
import { NotificationCard } from "./notification/index.js";
|
||||
import { NotificationPager } from "./pager/index.js";
|
||||
import { Notification } from 'types/service/notifications.js';
|
||||
import DropdownMenu from '../DropdownMenu.js';
|
||||
const notifs = await Service.import('notifications');
|
||||
import { Controls } from './controls/index.js';
|
||||
import { NotificationCard } from './notification/index.js';
|
||||
import { NotificationPager } from './pager/index.js';
|
||||
|
||||
import options from "options";
|
||||
import options from 'options';
|
||||
import Window from 'types/widgets/window.js';
|
||||
import { Attribute, Child } from 'lib/types/widget.js';
|
||||
|
||||
const { displayedTotal } = options.notifications;
|
||||
|
||||
export default () => {
|
||||
export default (): Window<Child, Attribute> => {
|
||||
const curPage = Variable(1);
|
||||
|
||||
Utils.merge(
|
||||
[
|
||||
curPage.bind("value"),
|
||||
displayedTotal.bind("value"),
|
||||
notifs.bind("notifications"),
|
||||
],
|
||||
(
|
||||
currentPage: number,
|
||||
dispTotal: number,
|
||||
notifications: Notification[],
|
||||
) => {
|
||||
[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",
|
||||
transition: "crossfade",
|
||||
name: 'notificationsmenu',
|
||||
transition: 'crossfade',
|
||||
child: Widget.Box({
|
||||
class_name: "notification-menu-content",
|
||||
css: "padding: 1px; margin: -1px;",
|
||||
class_name: 'notification-menu-content',
|
||||
css: 'padding: 1px; margin: -1px;',
|
||||
hexpand: true,
|
||||
vexpand: false,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "notification-card-container menu",
|
||||
class_name: 'notification-card-container menu',
|
||||
vertical: true,
|
||||
hexpand: false,
|
||||
vexpand: false,
|
||||
children: [Controls(notifs), NotificationCard(notifs, curPage), NotificationPager(curPage)]
|
||||
children: [Controls(notifs), NotificationCard(notifs, curPage), NotificationPager(curPage)],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
import { Notification, Notifications } from "types/service/notifications";
|
||||
const Actions = (notif: Notification, notifs: Notifications) => {
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { Notification, Notifications } from 'types/service/notifications';
|
||||
const Actions = (notif: Notification, notifs: Notifications): BoxWidget => {
|
||||
if (notif.actions !== undefined && notif.actions.length > 0) {
|
||||
return Widget.Box({
|
||||
class_name: "notification-card-actions menu",
|
||||
class_name: 'notification-card-actions menu',
|
||||
hexpand: true,
|
||||
vpack: "end",
|
||||
vpack: 'end',
|
||||
children: notif.actions.map((action) => {
|
||||
return Widget.Button({
|
||||
hexpand: true,
|
||||
class_name: "notification-action-buttons menu",
|
||||
class_name: 'notification-action-buttons menu',
|
||||
on_primary_click: () => {
|
||||
if (action.id.includes("scriptAction:-")) {
|
||||
App.closeWindow("notificationsmenu");
|
||||
Utils.execAsync(
|
||||
`${action.id.replace("scriptAction:-", "")}`,
|
||||
).catch((err) => console.error(err));
|
||||
if (action.id.includes('scriptAction:-')) {
|
||||
App.closeWindow('notificationsmenu');
|
||||
Utils.execAsync(`${action.id.replace('scriptAction:-', '')}`).catch((err) =>
|
||||
console.error(err),
|
||||
);
|
||||
notifs.CloseNotification(notif.id);
|
||||
} else {
|
||||
App.closeWindow("notificationsmenu");
|
||||
App.closeWindow('notificationsmenu');
|
||||
notif.invoke(action.id);
|
||||
}
|
||||
},
|
||||
child: Widget.Box({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
hexpand: true,
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "notification-action-buttons-label menu",
|
||||
class_name: 'notification-action-buttons-label menu',
|
||||
hexpand: true,
|
||||
max_width_chars: 15,
|
||||
truncate: "end",
|
||||
truncate: 'end',
|
||||
wrap: true,
|
||||
label: action.label,
|
||||
}),
|
||||
@@ -41,7 +42,7 @@ const Actions = (notif: Notification, notifs: Notifications) => {
|
||||
}
|
||||
|
||||
return Widget.Box({
|
||||
class_name: "spacer",
|
||||
class_name: 'spacer',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
import { notifHasImg } from "../../utils.js";
|
||||
import { Notification } from "types/service/notifications";
|
||||
import { BoxWidget } from 'lib/types/widget.js';
|
||||
import { notifHasImg } from '../../utils.js';
|
||||
import { Notification } from 'types/service/notifications';
|
||||
|
||||
export const Body = (notif: Notification) => {
|
||||
export const Body = (notif: Notification): BoxWidget => {
|
||||
return Widget.Box({
|
||||
vpack: "start",
|
||||
vpack: 'start',
|
||||
hexpand: true,
|
||||
class_name: "notification-card-body menu",
|
||||
class_name: 'notification-card-body menu',
|
||||
children: [
|
||||
Widget.Label({
|
||||
hexpand: true,
|
||||
use_markup: true,
|
||||
xalign: 0,
|
||||
justification: "left",
|
||||
truncate: "end",
|
||||
justification: 'left',
|
||||
truncate: 'end',
|
||||
lines: 2,
|
||||
max_width_chars: !notifHasImg(notif) ? 35 : 28,
|
||||
wrap: true,
|
||||
class_name: "notification-card-body-label menu",
|
||||
label: notif["body"],
|
||||
class_name: 'notification-card-body-label menu',
|
||||
label: notif['body'],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { Notification, Notifications } from "types/service/notifications";
|
||||
export const CloseButton = (notif: Notification, notifs: Notifications) => {
|
||||
import { Attribute } from 'lib/types/widget';
|
||||
import { Notification, Notifications } from 'types/service/notifications';
|
||||
import Button from 'types/widgets/button';
|
||||
import Label from 'types/widgets/label';
|
||||
export const CloseButton = (notif: Notification, notifs: Notifications): Button<Label<Attribute>, Attribute> => {
|
||||
return Widget.Button({
|
||||
class_name: "close-notification-button menu",
|
||||
class_name: 'close-notification-button menu',
|
||||
on_primary_click: () => {
|
||||
notifs.CloseNotification(notif.id);
|
||||
},
|
||||
child: Widget.Label({
|
||||
class_name: "txt-icon notif-close",
|
||||
label: "",
|
||||
hpack: "center",
|
||||
class_name: 'txt-icon notif-close',
|
||||
label: '',
|
||||
hpack: 'center',
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Notification } from "types/service/notifications.js";
|
||||
import { NotificationIcon } from "lib/types/notification.js";
|
||||
import { getNotificationIcon } from "globals/notification";
|
||||
import { Notification } from 'types/service/notifications.js';
|
||||
import { NotificationIcon } from 'lib/types/notification.js';
|
||||
import { getNotificationIcon } from 'globals/notification';
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
|
||||
const NotificationIcon = ({ app_entry = "", app_icon = "", app_name = "" }: Partial<Notification>) => {
|
||||
const NotificationIcon = ({ app_entry = '', app_icon = '', app_name = '' }: Partial<Notification>): BoxWidget => {
|
||||
return Widget.Box({
|
||||
css: `
|
||||
min-width: 2rem;
|
||||
min-height: 2rem;
|
||||
`,
|
||||
child: Widget.Icon({
|
||||
class_name: "notification-icon menu",
|
||||
class_name: 'notification-icon menu',
|
||||
icon: getNotificationIcon(app_name, app_icon, app_entry),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1,50 +1,51 @@
|
||||
import GLib from "gi://GLib";
|
||||
import { Notification } from "types/service/notifications";
|
||||
import { NotificationIcon } from "./icon.js";
|
||||
import { notifHasImg } from "../../utils.js";
|
||||
import options from "options.js";
|
||||
import GLib from 'gi://GLib';
|
||||
import { Notification } from 'types/service/notifications';
|
||||
import { NotificationIcon } from './icon.js';
|
||||
import { notifHasImg } from '../../utils.js';
|
||||
import options from 'options.js';
|
||||
import { BoxWidget } from 'lib/types/widget.js';
|
||||
|
||||
const { military } = options.menus.clock.time;
|
||||
|
||||
export const Header = (notif: Notification) => {
|
||||
const time = (time: number, format = "%I:%M %p") => {
|
||||
return GLib.DateTime.new_from_unix_local(time).format(military.value ? "%H:%M" : format);
|
||||
}
|
||||
export const Header = (notif: Notification): BoxWidget => {
|
||||
const time = (time: number, format = '%I:%M %p'): string => {
|
||||
return GLib.DateTime.new_from_unix_local(time).format(military.value ? '%H:%M' : format) || '--:--';
|
||||
};
|
||||
|
||||
return Widget.Box({
|
||||
vertical: false,
|
||||
hexpand: true,
|
||||
children: [
|
||||
Widget.Box({
|
||||
class_name: "notification-card-header menu",
|
||||
hpack: "start",
|
||||
class_name: 'notification-card-header menu',
|
||||
hpack: 'start',
|
||||
children: [NotificationIcon(notif)],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "notification-card-header menu",
|
||||
class_name: 'notification-card-header menu',
|
||||
hexpand: true,
|
||||
vpack: "start",
|
||||
vpack: 'start',
|
||||
children: [
|
||||
Widget.Label({
|
||||
class_name: "notification-card-header-label menu",
|
||||
hpack: "start",
|
||||
class_name: 'notification-card-header-label menu',
|
||||
hpack: 'start',
|
||||
hexpand: true,
|
||||
vexpand: true,
|
||||
max_width_chars: !notifHasImg(notif) ? 34 : 22,
|
||||
truncate: "end",
|
||||
truncate: 'end',
|
||||
wrap: true,
|
||||
label: notif["summary"],
|
||||
label: notif['summary'],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
class_name: "notification-card-header menu",
|
||||
hpack: "end",
|
||||
vpack: "start",
|
||||
class_name: 'notification-card-header menu',
|
||||
hpack: 'end',
|
||||
vpack: 'start',
|
||||
hexpand: true,
|
||||
child: Widget.Label({
|
||||
vexpand: true,
|
||||
class_name: "notification-time",
|
||||
class_name: 'notification-time',
|
||||
label: time(notif.time),
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { Notification } from "types/service/notifications";
|
||||
import { notifHasImg } from "../../utils.js";
|
||||
import { Notification } from 'types/service/notifications';
|
||||
import { notifHasImg } from '../../utils.js';
|
||||
import { BoxWidget } from 'lib/types/widget.js';
|
||||
|
||||
const Image = (notif: Notification) => {
|
||||
const Image = (notif: Notification): BoxWidget => {
|
||||
if (notifHasImg(notif)) {
|
||||
return Widget.Box({
|
||||
class_name: "notification-card-image-container menu",
|
||||
hpack: "center",
|
||||
vpack: "center",
|
||||
class_name: 'notification-card-image-container menu',
|
||||
hpack: 'center',
|
||||
vpack: 'center',
|
||||
vexpand: false,
|
||||
child: Widget.Box({
|
||||
hpack: "center",
|
||||
hpack: 'center',
|
||||
vexpand: false,
|
||||
class_name: "notification-card-image menu",
|
||||
class_name: 'notification-card-image menu',
|
||||
css: `background-image: url("${notif.image}")`,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1,45 +1,40 @@
|
||||
import { Notifications, Notification } from "types/service/notifications";
|
||||
import { notifHasImg } from "../utils.js";
|
||||
import { Header } from "./header/index.js";
|
||||
import { Actions } from "./actions/index.js";
|
||||
import { Image } from "./image/index.js";
|
||||
import { Placeholder } from "./placeholder/index.js";
|
||||
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";
|
||||
import { Notifications, Notification } from 'types/service/notifications';
|
||||
import { notifHasImg } from '../utils.js';
|
||||
import { Header } from './header/index.js';
|
||||
import { Actions } from './actions/index.js';
|
||||
import { Image } from './image/index.js';
|
||||
import { Placeholder } from './placeholder/index.js';
|
||||
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';
|
||||
import Scrollable from 'types/widgets/scrollable.js';
|
||||
import { Attribute, Child } from 'lib/types/widget.js';
|
||||
|
||||
const { displayedTotal, ignore } = options.notifications;
|
||||
|
||||
const NotificationCard = (notifs: Notifications, curPage: Variable<number>) => {
|
||||
const NotificationCard = (notifs: Notifications, curPage: Variable<number>): Scrollable<Child, Attribute> => {
|
||||
return Widget.Scrollable({
|
||||
vscroll: "automatic",
|
||||
vscroll: 'automatic',
|
||||
child: Widget.Box({
|
||||
class_name: "menu-content-container notifications",
|
||||
hpack: "center",
|
||||
class_name: 'menu-content-container notifications',
|
||||
hpack: 'center',
|
||||
vexpand: true,
|
||||
spacing: 0,
|
||||
vertical: true,
|
||||
setup: (self) => {
|
||||
Utils.merge(
|
||||
[
|
||||
notifs.bind("notifications"),
|
||||
curPage.bind("value"),
|
||||
displayedTotal.bind("value"),
|
||||
ignore.bind("value")
|
||||
notifs.bind('notifications'),
|
||||
curPage.bind('value'),
|
||||
displayedTotal.bind('value'),
|
||||
ignore.bind('value'),
|
||||
],
|
||||
(
|
||||
notifications,
|
||||
currentPage,
|
||||
dispTotal,
|
||||
ignoredNotifs
|
||||
) => {
|
||||
(notifications, currentPage, dispTotal, ignoredNotifs) => {
|
||||
const filteredNotifications = filterNotifications(notifications, ignoredNotifs);
|
||||
|
||||
const sortedNotifications = filteredNotifications.sort(
|
||||
(a, b) => b.time - a.time,
|
||||
);
|
||||
const sortedNotifications = filteredNotifications.sort((a, b) => b.time - a.time);
|
||||
|
||||
if (filteredNotifications.length <= 0) {
|
||||
return (self.children = [Placeholder(notifs)]);
|
||||
@@ -47,37 +42,36 @@ const NotificationCard = (notifs: Notifications, curPage: Variable<number>) => {
|
||||
|
||||
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),
|
||||
],
|
||||
});
|
||||
}));
|
||||
});
|
||||
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),
|
||||
],
|
||||
});
|
||||
}));
|
||||
},
|
||||
);
|
||||
},
|
||||
})
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
import { Notifications } from "types/service/notifications";
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
import { Notifications } from 'types/service/notifications';
|
||||
|
||||
const Placeholder = (notifs: Notifications) => {
|
||||
const Placeholder = (notifs: Notifications): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: "notification-label-container",
|
||||
vpack: "fill",
|
||||
hpack: "center",
|
||||
class_name: 'notification-label-container',
|
||||
vpack: 'fill',
|
||||
hpack: 'center',
|
||||
expand: true,
|
||||
child: Widget.Box({
|
||||
vpack: "center",
|
||||
vpack: 'center',
|
||||
vertical: true,
|
||||
expand: true,
|
||||
children: [
|
||||
Widget.Label({
|
||||
vpack: "center",
|
||||
class_name: "placeholder-label dim bell",
|
||||
label: notifs.bind("dnd").as((dnd) => (dnd ? "" : "")),
|
||||
vpack: 'center',
|
||||
class_name: 'placeholder-label dim bell',
|
||||
label: notifs.bind('dnd').as((dnd) => (dnd ? '' : '')),
|
||||
}),
|
||||
Widget.Label({
|
||||
vpack: "start",
|
||||
class_name: "placehold-label dim message",
|
||||
vpack: 'start',
|
||||
class_name: 'placehold-label dim message',
|
||||
label: "You're all caught up :)",
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -1,91 +1,88 @@
|
||||
const notifs = await Service.import("notifications");
|
||||
const notifs = await Service.import('notifications');
|
||||
|
||||
import options from "options";
|
||||
import { Notification } from "types/service/notifications";
|
||||
import { Variable } from "types/variable";
|
||||
import { BoxWidget } from 'lib/types/widget';
|
||||
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>) => {
|
||||
export const NotificationPager = (curPage: Variable<number>): BoxWidget => {
|
||||
return Widget.Box({
|
||||
class_name: "notification-menu-pager",
|
||||
class_name: 'notification-menu-pager',
|
||||
hexpand: true,
|
||||
vexpand: false,
|
||||
children: Utils.merge(
|
||||
[
|
||||
curPage.bind("value"),
|
||||
displayedTotal.bind("value"),
|
||||
notifs.bind("notifications"),
|
||||
showPager.bind("value")
|
||||
curPage.bind('value'),
|
||||
displayedTotal.bind('value'),
|
||||
notifs.bind('notifications'),
|
||||
showPager.bind('value'),
|
||||
],
|
||||
(
|
||||
currentPage: number,
|
||||
dispTotal: number,
|
||||
_: Notification[],
|
||||
showPgr: boolean
|
||||
) => {
|
||||
(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" : ""}`,
|
||||
hpack: 'start',
|
||||
class_name: `pager-button left ${currentPage <= 1 ? 'disabled' : ''}`,
|
||||
onPrimaryClick: () => {
|
||||
curPage.value = 1;
|
||||
},
|
||||
child: Widget.Label({
|
||||
className: "pager-button-label",
|
||||
label: ""
|
||||
className: 'pager-button-label',
|
||||
label: '',
|
||||
}),
|
||||
}),
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "start",
|
||||
class_name: `pager-button left ${currentPage <= 1 ? "disabled" : ""}`,
|
||||
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: ""
|
||||
className: 'pager-button-label',
|
||||
label: '',
|
||||
}),
|
||||
}),
|
||||
Widget.Label({
|
||||
hexpand: true,
|
||||
hpack: "center",
|
||||
class_name: "pager-label",
|
||||
label: `${currentPage} / ${Math.ceil(notifs.notifications.length / dispTotal) || 1}`
|
||||
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" : ""}`,
|
||||
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: ""
|
||||
className: 'pager-button-label',
|
||||
label: '',
|
||||
}),
|
||||
}),
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
hpack: "end",
|
||||
class_name: `pager-button right ${currentPage >= Math.ceil(notifs.notifications.length / dispTotal) ? "disabled" : ""}`,
|
||||
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: ""
|
||||
className: 'pager-button-label',
|
||||
label: '',
|
||||
}),
|
||||
}),
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
];
|
||||
},
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Notification } from "types/service/notifications";
|
||||
import { Notification } from 'types/service/notifications';
|
||||
|
||||
const notifHasImg = (notif: Notification) => {
|
||||
return notif.image !== undefined && notif.image.length;
|
||||
const notifHasImg = (notif: Notification): boolean => {
|
||||
return notif.image !== undefined && notif.image.length ? true : false;
|
||||
};
|
||||
|
||||
export { notifHasImg };
|
||||
|
||||
Reference in New Issue
Block a user