2023-10-11 15:45:03 -04:00
|
|
|
import { Notifications, Widget } from '../../imports.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
const { Box, Revealer, Window } = Widget;
|
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
import Notification from './base.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
|
|
|
|
const Popups = () => Box({
|
2023-09-11 14:18:22 -04:00
|
|
|
vertical: true,
|
|
|
|
properties: [
|
|
|
|
['map', new Map()],
|
|
|
|
['dismiss', (box, id, force = false) => {
|
|
|
|
if (!id || !box._map.has(id))
|
|
|
|
return;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-09-11 14:18:22 -04:00
|
|
|
if (box._map.get(id)._hovered && !force)
|
|
|
|
return;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-09-11 14:18:22 -04:00
|
|
|
if (box._map.size - 1 === 0)
|
|
|
|
box.get_parent().reveal_child = false;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-10-11 15:45:03 -04:00
|
|
|
setTimeout(() => {
|
2023-09-21 00:40:16 -04:00
|
|
|
if (box._map.get(id)?.interval) {
|
2023-10-11 15:45:03 -04:00
|
|
|
box._map.get(id).interval.destroy();
|
2023-09-14 17:24:40 -04:00
|
|
|
box._map.get(id).interval = undefined;
|
2023-09-14 17:24:02 -04:00
|
|
|
}
|
2023-09-11 14:18:22 -04:00
|
|
|
box._map.get(id)?.destroy();
|
|
|
|
box._map.delete(id);
|
2023-10-11 15:45:03 -04:00
|
|
|
}, 200);
|
2023-09-11 14:18:22 -04:00
|
|
|
}],
|
|
|
|
['notify', (box, id) => {
|
|
|
|
if (!id || Notifications.dnd)
|
|
|
|
return;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-09-19 10:22:08 -04:00
|
|
|
if (! Notifications.getNotification(id))
|
|
|
|
return;
|
|
|
|
|
2023-09-11 14:18:22 -04:00
|
|
|
box._map.delete(id);
|
2023-09-14 17:24:02 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
let notif = Notifications.getNotification(id);
|
2023-09-14 17:24:02 -04:00
|
|
|
box._map.set(id, Notification({
|
2023-10-02 12:06:35 -04:00
|
|
|
notif,
|
|
|
|
command: () => notif.dismiss(),
|
2023-09-14 17:24:02 -04:00
|
|
|
}));
|
|
|
|
|
2023-09-11 14:18:22 -04:00
|
|
|
box.children = Array.from(box._map.values()).reverse();
|
2023-10-11 15:45:03 -04:00
|
|
|
setTimeout(() => {
|
2023-09-11 14:18:22 -04:00
|
|
|
box.get_parent().revealChild = true;
|
2023-10-11 15:45:03 -04:00
|
|
|
}, 10);
|
|
|
|
box._map.get(id).interval = setInterval(() => {
|
|
|
|
print('interval')
|
2023-09-14 16:42:39 -04:00
|
|
|
if (!box._map.get(id)._hovered) {
|
2023-09-21 00:27:58 -04:00
|
|
|
box._map.get(id).child.setStyle(box._map.get(id).child._leftAnim1);
|
2023-09-14 16:42:39 -04:00
|
|
|
|
2023-09-14 17:24:02 -04:00
|
|
|
if (box._map.get(id).interval) {
|
2023-10-11 15:45:03 -04:00
|
|
|
box._map.get(id).interval.destroy();
|
2023-09-14 17:24:40 -04:00
|
|
|
box._map.get(id).interval = undefined;
|
2023-09-14 16:42:39 -04:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 15:45:03 -04:00
|
|
|
}, 4500);
|
2023-09-11 14:18:22 -04:00
|
|
|
}],
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[Notifications, (box, id) => box._notify(box, id), 'notified'],
|
|
|
|
[Notifications, (box, id) => box._dismiss(box, id), 'dismissed'],
|
|
|
|
[Notifications, (box, id) => box._dismiss(box, id, true), 'closed'],
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-09-14 16:42:39 -04:00
|
|
|
const PopupList = ({ transition = 'none' } = {}) => Box({
|
2023-09-11 14:18:22 -04:00
|
|
|
className: 'notifications-popup-list',
|
|
|
|
style: 'padding: 1px',
|
|
|
|
children: [
|
|
|
|
Revealer({
|
|
|
|
transition,
|
|
|
|
child: Popups(),
|
|
|
|
}),
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export const NotificationsPopupList = Window({
|
2023-09-11 14:18:22 -04:00
|
|
|
name: `notifications`,
|
2023-10-07 21:02:23 -04:00
|
|
|
anchor: [ 'top', 'left' ],
|
2023-09-11 14:18:22 -04:00
|
|
|
child: PopupList(),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|