Files
custum-hyprpanel/modules/menus/notifications/index.ts
Jas Singh ee7d19320c Refactored hooks to specify events and reworked the dropdowns to be significantly faster and more responsive. (#304)
* Updated events to be more specific

* Update more events

* Update globalmousepos

* Update themes and submap module to show submap name.

* Type fixes

* Reworked menu position calculation logic to be much more efficient.

* Revert import file location

* We luv arrow functions

* Remove globalMousePos remnants since it's unused.

* Added the ability to configure menu dropdown transition and duration.

* Fix type
2024-10-06 00:22:27 -07:00

48 lines
1.8 KiB
TypeScript

import { Notification } from 'types/service/notifications.js';
import DropdownMenu from '../shared/dropdown/index.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 Window from 'types/widgets/window.js';
import { Attribute, Child } from 'lib/types/widget.js';
const { displayedTotal } = options.notifications;
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[]) => {
// 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: options.menus.transition.bind('value'),
child: Widget.Box({
class_name: 'notification-menu-content',
css: 'padding: 1px; margin: -1px;',
hexpand: true,
vexpand: false,
children: [
Widget.Box({
class_name: 'notification-card-container menu',
vertical: true,
hexpand: false,
vexpand: false,
children: [Controls(notifs), NotificationCard(notifs, curPage), NotificationPager(curPage)],
}),
],
}),
});
};