mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
879aa2c3d8
* feat: watchers notification and email preferences * fix: email copy * digests * clean up * fix * clean up * move backlinks queue-up to history processor * fix * fix keys * feat: group notifications * filter * adjust email digest window
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import {
|
|
keepPreviousData,
|
|
useInfiniteQuery,
|
|
useMutation,
|
|
useQuery,
|
|
useQueryClient,
|
|
} from "@tanstack/react-query";
|
|
import {
|
|
getNotifications,
|
|
getUnreadCount,
|
|
markNotificationsRead,
|
|
markAllNotificationsRead,
|
|
} from "../services/notification-service";
|
|
|
|
export const NOTIFICATION_KEY = ["notifications"];
|
|
export const UNREAD_COUNT_KEY = ["notifications", "unread-count"];
|
|
|
|
export function useNotificationsQuery(type?: string) {
|
|
return useInfiniteQuery({
|
|
queryKey: [...NOTIFICATION_KEY, type],
|
|
queryFn: ({ pageParam }) => getNotifications({ cursor: pageParam, type }),
|
|
initialPageParam: undefined as string | undefined,
|
|
getNextPageParam: (lastPage) =>
|
|
lastPage.meta.hasNextPage ? lastPage.meta.nextCursor : undefined,
|
|
staleTime: 0,
|
|
gcTime: 0,
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
}
|
|
|
|
export function useUnreadCountQuery() {
|
|
return useQuery({
|
|
queryKey: UNREAD_COUNT_KEY,
|
|
queryFn: getUnreadCount,
|
|
});
|
|
}
|
|
|
|
export function useMarkReadMutation() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (notificationIds: string[]) =>
|
|
markNotificationsRead(notificationIds),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: NOTIFICATION_KEY });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useMarkAllReadMutation() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: markAllNotificationsRead,
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: NOTIFICATION_KEY });
|
|
},
|
|
});
|
|
}
|