From b2ac76f417db507075146654c0a3c8312b509ae8 Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Fri, 24 May 2024 21:58:00 +0200 Subject: [PATCH] temp(notifications): Temporarily mock a notification system --- desktop/src/bridge/notifications.ts | 52 +++++++++++++++---- .../notifications/NotificationOverlay.tsx | 3 ++ .../notifications/NotificationPopup.tsx | 22 ++++---- 3 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 desktop/src/ui/components/overlay/notifications/NotificationOverlay.tsx diff --git a/desktop/src/bridge/notifications.ts b/desktop/src/bridge/notifications.ts index 431d9b2a..972ec015 100644 --- a/desktop/src/bridge/notifications.ts +++ b/desktop/src/bridge/notifications.ts @@ -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): Promise { - 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 { - 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 { - await invoke('plugin:onelauncher|notifications_clear'); + _notifications = []; + emitter.emit('cleared'); + // await invoke('plugin:onelauncher|notifications_clear'); } export async function getNotifications(): Promise { - 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 { - return await listen(`notifications_event`, (e) => { - if (e.payload.toLowerCase() === event) + emitter.on((e) => { + if (event === e) callback(); }); + return () => {}; + // return await listen(`notifications_event`, (e) => { + // if (e.payload.toLowerCase() === event) + // callback(); + // }); }; diff --git a/desktop/src/ui/components/overlay/notifications/NotificationOverlay.tsx b/desktop/src/ui/components/overlay/notifications/NotificationOverlay.tsx new file mode 100644 index 00000000..8f1076cb --- /dev/null +++ b/desktop/src/ui/components/overlay/notifications/NotificationOverlay.tsx @@ -0,0 +1,3 @@ +export default function NotificationOverlay() { + +} diff --git a/desktop/src/ui/components/overlay/notifications/NotificationPopup.tsx b/desktop/src/ui/components/overlay/notifications/NotificationPopup.tsx index 5b62284a..b90e9286 100644 --- a/desktop/src/ui/components/overlay/notifications/NotificationPopup.tsx +++ b/desktop/src/ui/components/overlay/notifications/NotificationPopup.tsx @@ -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) {

Notifications

+ {notifications().length} + - + 0}>
- {noti => ( -
- - -
- )} + {(noti) => { + console.log(noti); + return ( +
+ + +
+ ); + }}