mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
05b3c65b0f
* feat: notifications * feat: watchers * improvements * handle page move for watchers * make watchers non-blocking * more
24 lines
674 B
TypeScript
24 lines
674 B
TypeScript
import { useEffect } from "react";
|
|
import { useAtom } from "jotai";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import { socketAtom } from "@/features/websocket/atoms/socket-atom";
|
|
import { NOTIFICATION_KEY } from "../queries/notification-query";
|
|
|
|
export function useNotificationSocket() {
|
|
const queryClient = useQueryClient();
|
|
const [socket] = useAtom(socketAtom);
|
|
|
|
useEffect(() => {
|
|
if (!socket) return;
|
|
|
|
const handler = () => {
|
|
queryClient.invalidateQueries({ queryKey: NOTIFICATION_KEY });
|
|
};
|
|
|
|
socket.on("notification", handler);
|
|
return () => {
|
|
socket.off("notification", handler);
|
|
};
|
|
}, [socket, queryClient]);
|
|
}
|