Files
custum-hyprpanel/src/components/menus/notifications/pager/index.tsx
Jas Singh 2bb1449fb6 Fix: An issue that would cause Matugen colors to not apply. (#929)
* Eslint updates

* linter fixes

* Type fixes

* More type fixes

* Fix isvis

* More type fixes

* Type Fixes

* Consolidate logic to manage options

* Linter fixes

* Package lock update

* Update configs

* Version checker

* Debug pipeline

* Package lock update

* Update ci

* Strict check

* Revert ci

* Eslint

* Remove rule since it causes issues in CI

* Actual matugen fix
2025-05-11 23:01:55 -07:00

82 lines
2.7 KiB
TypeScript

import { bind, Variable } from 'astal';
import { Gtk } from 'astal/gtk3';
import AstalNotifd from 'gi://AstalNotifd?version=0.1';
import options from 'src/options';
import { FirstPageButton, LastPageButton, NextPageButton, PreviousPageButton } from './Buttons';
const notifdService = AstalNotifd.get_default();
const { displayedTotal } = options.notifications;
const { show: showPager } = options.theme.bar.menus.menu.notifications.pager;
const PageDisplay = ({ notifications, currentPage, dispTotal }: PageDisplayProps): JSX.Element => {
return (
<label
hexpand={true}
halign={Gtk.Align.CENTER}
className={'pager-label'}
label={`${currentPage} / ${Math.ceil(notifications.length / dispTotal) || 1}`}
/>
);
};
export const NotificationPager = ({ curPage }: NotificationPagerProps): JSX.Element => {
const pagerBinding = Variable.derive(
[bind(curPage), bind(displayedTotal), bind(notifdService, 'notifications'), bind(showPager)],
(currentPage, dispTotal, notifications, showPgr) => {
if (showPgr === false || (currentPage === 1 && notifications.length <= dispTotal)) {
return <box />;
}
return (
<box>
<FirstPageButton curPage={curPage} currentPage={currentPage} />
<PreviousPageButton curPage={curPage} currentPage={currentPage} />
<PageDisplay
notifications={notifications}
currentPage={currentPage}
dispTotal={dispTotal}
/>
<NextPageButton
curPage={curPage}
currentPage={currentPage}
notifications={notifications}
displayedTotal={displayedTotal}
dispTotal={dispTotal}
/>
<LastPageButton
curPage={curPage}
currentPage={currentPage}
notifications={notifications}
displayedTotal={displayedTotal}
dispTotal={dispTotal}
/>
</box>
);
},
);
return (
<box
className={'notification-menu-pager'}
hexpand={true}
vexpand={false}
onDestroy={() => {
pagerBinding.drop();
}}
>
{pagerBinding()}
</box>
);
};
interface NotificationPagerProps {
curPage: Variable<number>;
}
interface PageDisplayProps {
notifications: AstalNotifd.Notification[];
currentPage: number;
dispTotal: number;
}