mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 13:05:44 +00:00
style: improve the ui of the toast for notifications
This commit is contained in:
@@ -4,8 +4,7 @@ import {
|
||||
type NotificationDto,
|
||||
} from "@edr/types";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { io } from "socket.io-client";
|
||||
|
||||
import { API_BASE_URL } from "@/constants/apiConfig";
|
||||
@@ -25,10 +24,16 @@ const SOCKET_ORIGIN = String(API_BASE_URL ?? "").replace(/\/api\/?$/, "");
|
||||
|
||||
/**
|
||||
* Subscribes to live notification pushes for the signed-in user. New items
|
||||
* invalidate the list + toast; unread-count pushes update the badge instantly.
|
||||
* invalidate the cached lists + fire `onNew` (the host shows a rich toast);
|
||||
* unread-count pushes update the badge instantly.
|
||||
*/
|
||||
export function useNotificationSocket(enabled: boolean) {
|
||||
export function useNotificationSocket(
|
||||
enabled: boolean,
|
||||
onNew?: (notification: NotificationDto) => void,
|
||||
) {
|
||||
const qc = useQueryClient();
|
||||
const onNewRef = useRef(onNew);
|
||||
onNewRef.current = onNew;
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
@@ -43,7 +48,8 @@ export function useNotificationSocket(enabled: boolean) {
|
||||
|
||||
socket.on(NOTIFICATION_WS_EVENTS.NEW, (n: NotificationDto) => {
|
||||
qc.invalidateQueries({ queryKey: NOTIFICATIONS_KEY });
|
||||
toast(n.title);
|
||||
qc.invalidateQueries({ queryKey: UNREAD_KEY });
|
||||
onNewRef.current?.(n);
|
||||
});
|
||||
|
||||
socket.on(NOTIFICATION_WS_EVENTS.UNREAD_COUNT, (count: number) => {
|
||||
|
||||
Reference in New Issue
Block a user