temp(notifications): Temporarily mock a notification system

This commit is contained in:
LynithDev 2024-05-24 21:58:00 +02:00
parent 78cea2ce5b
commit b2ac76f417
3 changed files with 57 additions and 20 deletions

View file

@ -12,26 +12,51 @@ export enum NotificationType {
Refresh = 'Refresh',
}
let _notifications: Core.Notification[] = [];
class _Emitter {
private listeners: ((event: string) => unknown)[] = [];
public emit(event: Core.NotificationEvents) {
this.listeners.forEach(value => value(event));
}
public on(callback: (event: string) => unknown) {
this.listeners.push(callback);
}
}
const emitter = new _Emitter();
export async function addNotification(notification: MakeOptional<Core.Notification, 'created_at'>): Promise<void> {
await invoke('plugin:onelauncher|notifications_add', {
notification: {
created_at: Math.floor(Date.now() / 1000),
...notification,
},
_notifications.push({
created_at: Math.floor(Date.now() / 1000),
...notification,
});
emitter.emit('added');
// await invoke('plugin:onelauncher|notifications_add', {
// notification: {
// created_at: Math.floor(Date.now() / 1000),
// ...notification,
// },
// });
}
export async function removeNotification(index: number): Promise<void> {
await invoke('plugin:onelauncher|notifications_remove_by_index', { index });
_notifications.splice(index, 1);
emitter.emit('removed');
// await invoke('plugin:onelauncher|notifications_remove_by_index', { index });
}
export async function clearNotifications(): Promise<void> {
await invoke('plugin:onelauncher|notifications_clear');
_notifications = [];
emitter.emit('cleared');
// await invoke('plugin:onelauncher|notifications_clear');
}
export async function getNotifications(): Promise<Core.Notification[]> {
return [];
return await invoke('plugin:onelauncher|notifications_get');
return [..._notifications];
// return await invoke('plugin:onelauncher|notifications_get');
}
export async function on<
@ -40,8 +65,13 @@ export async function on<
event: T,
callback: () => void,
): Promise<UnlistenFn> {
return await listen<string>(`notifications_event`, (e) => {
if (e.payload.toLowerCase() === event)
emitter.on((e) => {
if (event === e)
callback();
});
return () => {};
// return await listen<string>(`notifications_event`, (e) => {
// if (e.payload.toLowerCase() === event)
// callback();
// });
};

View file

@ -0,0 +1,3 @@
export default function NotificationOverlay() {
}

View file

@ -1,4 +1,4 @@
import { For, Match, Switch, createSignal, onMount } from 'solid-js';
import { For, Match, Switch, createEffect, createSignal, onMount } from 'solid-js';
import { Settings01Icon, Trash01Icon } from '@untitled-theme/icons-solid';
import { OverlayScrollbarsComponent } from 'overlayscrollbars-solid';
import Popup from '../Popup';
@ -23,7 +23,6 @@ function NotificationPopup(props: Popup.PopupProps) {
const notis = await manager.getNotifications();
setNotifications(notis);
updateSize();
console.log(notifications());
}
onMount(() => {
@ -51,17 +50,22 @@ function NotificationPopup(props: Popup.PopupProps) {
<div class="flex flex-col justify-start items-stretch text-start gap-2" ref={inner}>
<p class="text-2lg px-2 pt-1">Notifications</p>
{notifications().length}
<Switch>
<Match when={notifications().length !== 0}>
<Match when={notifications().length > 0}>
<OverlayScrollbarsComponent class="max-h-[min(500px,60vh)] overflow-auto">
<div class="flex flex-col-reverse justify-center items-stretch ">
<For each={notifications()}>
{noti => (
<div class="flex flex-col w-full">
<NotificationComponent data={noti} overlay={false} />
<span class="bg-gray-05 h-px w-full" />
</div>
)}
{(noti) => {
console.log(noti);
return (
<div class="flex flex-col w-full">
<NotificationComponent data={noti} overlay={false} />
<span class="bg-gray-05 h-px w-full" />
</div>
);
}}
</For>
</div>
</OverlayScrollbarsComponent>