notif clear button hide when empty

This commit is contained in:
end-4
2024-03-25 18:06:45 +07:00
parent 783f9ae518
commit 75e03d609b
2 changed files with 26 additions and 7 deletions
@@ -4,7 +4,7 @@ import { MaterialIcon } from './materialicon.js';
import { setupCursorHover } from '../.widgetutils/cursorhover.js'; import { setupCursorHover } from '../.widgetutils/cursorhover.js';
const { Box, Button, Label, Revealer } = Widget; const { Box, Button, Label, Revealer } = Widget;
export const ConfigToggle = ({ icon, name, desc = '', initValue, onChange, ...rest }) => { export const ConfigToggle = ({ icon, name, desc = '', initValue, onChange, expandWidget = true, ...rest }) => {
let value = initValue; let value = initValue;
const toggleIcon = Label({ const toggleIcon = Label({
className: `icon-material txt-bold ${value ? '' : 'txt-poof'}`, className: `icon-material txt-bold ${value ? '' : 'txt-poof'}`,
@@ -32,7 +32,7 @@ export const ConfigToggle = ({ icon, name, desc = '', initValue, onChange, ...re
className: 'txt txt-small', className: 'txt txt-small',
label: name, label: name,
}), }),
Box({ hexpand: true }), expandWidget ? Box({ hexpand: true }) : null,
toggleButton, toggleButton,
] ]
}); });
@@ -3,10 +3,11 @@
// The actual widget for each single notification is in ags/modules/.commonwidgets/notification.js // The actual widget for each single notification is in ags/modules/.commonwidgets/notification.js
import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js'; import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
const { Box, Button, Label, Scrollable, Stack } = Widget; const { Box, Button, Label, Revealer, Scrollable, Stack } = Widget;
import { MaterialIcon } from '../../.commonwidgets/materialicon.js'; import { MaterialIcon } from '../../.commonwidgets/materialicon.js';
import { setupCursorHover } from '../../.widgetutils/cursorhover.js'; import { setupCursorHover } from '../../.widgetutils/cursorhover.js';
import Notification from '../../.commonwidgets/notification.js'; import Notification from '../../.commonwidgets/notification.js';
import { ConfigToggle } from '../../.commonwidgets/configwidgets.js';
export default (props) => { export default (props) => {
const notifEmptyContent = Box({ const notifEmptyContent = Box({
@@ -84,10 +85,26 @@ export default (props) => {
Notifications.dnd = !Notifications.dnd; Notifications.dnd = !Notifications.dnd;
self.toggleClassName('notif-listaction-btn-enabled', Notifications.dnd); self.toggleClassName('notif-listaction-btn-enabled', Notifications.dnd);
}); });
const clearButton = ListActionButton('clear_all', 'Clear', () => { // const silenceToggle = ConfigToggle({
Notifications.clear(); // expandWidget: false,
notificationList.get_children().forEach(ch => ch.attribute.destroyWithAnims()) // icon: 'do_not_disturb_on',
}); // name: 'Do Not Disturb',
// initValue: false,
// onChange: (self, newValue) => {
// Notifications.dnd = newValue;
// },
// })
const clearButton = Revealer({
transition: 'slide_right',
transitionDuration: userOptions.animations.durationSmall,
setup: (self) => self.hook(Notifications, (self) => {
self.revealChild = Notifications.notifications.length > 0;
}),
child: ListActionButton('clear_all', 'Clear', () => {
Notifications.clear();
notificationList.get_children().forEach(ch => ch.attribute.destroyWithAnims())
})
})
const notifCount = Label({ const notifCount = Label({
attribute: { attribute: {
updateCount: (self) => { updateCount: (self) => {
@@ -112,6 +129,8 @@ export default (props) => {
children: [ children: [
notifCount, notifCount,
silenceButton, silenceButton,
// silenceToggle,
// Box({ hexpand: true }),
clearButton, clearButton,
] ]
}); });