2025-11-30 23:01:52 +11:00
|
|
|
import type { SerializeObject } from "nitropack";
|
2025-07-25 07:28:00 -04:00
|
|
|
import type { NotificationModel } from "~/prisma/client/models";
|
2024-11-16 19:41:19 +11:00
|
|
|
|
|
|
|
|
const ws = new WebSocketHandler("/api/v1/notifications/ws");
|
|
|
|
|
|
|
|
|
|
export const useNotifications = () =>
|
2025-11-30 23:01:52 +11:00
|
|
|
useState<Array<SerializeObject<NotificationModel>>>(
|
|
|
|
|
"notifications",
|
|
|
|
|
() => [],
|
|
|
|
|
);
|
2024-11-16 19:41:19 +11:00
|
|
|
|
|
|
|
|
ws.listen((e) => {
|
2025-11-30 23:01:52 +11:00
|
|
|
const notification = JSON.parse(e) as SerializeObject<NotificationModel>;
|
2024-11-16 19:41:19 +11:00
|
|
|
const notifications = useNotifications();
|
|
|
|
|
notifications.value.push(notification);
|
|
|
|
|
});
|