21 lines
737 B
TypeScript
21 lines
737 B
TypeScript
import * as api from "../service/NotificationService";
|
|
import { useInfiniteQuery, useMutation } from "@tanstack/react-query";
|
|
|
|
export const useGetNotification = (status: "all" | "seen" | "unseen") => {
|
|
return useInfiniteQuery({
|
|
queryKey: ["notifications", status],
|
|
queryFn: ({ pageParam }) =>
|
|
api.getNotifications(pageParam as string | undefined, status), // فراخوانی API برای گرفتن دادهها
|
|
initialPageParam: undefined as string | undefined, // اولین درخواست بدون cursor
|
|
getNextPageParam: (lastPage) => {
|
|
return lastPage.nextCursor || undefined;
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useReadAll = () => {
|
|
return useMutation({
|
|
mutationFn: () => api.readAll(),
|
|
});
|
|
};
|