notification infiti scroll
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
import * as api from "../service/NotificationService";
|
||||
import { useInfiniteQuery, useMutation } from "@tanstack/react-query";
|
||||
|
||||
export const useGetNotification = (status: "all" | "read" | "unread") => {
|
||||
export const useGetNotification = (status: "all" | "seen" | "unseen") => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ["notifications", status],
|
||||
queryFn: ({ pageParam = 1 }) => api.getNotifications(pageParam, status), // فراخوانی API برای گرفتن دادهها
|
||||
initialPageParam: 1, // صفحه اول به طور پیشفرض
|
||||
queryFn: ({ pageParam }) =>
|
||||
api.getNotifications(pageParam as string | undefined, status), // فراخوانی API برای گرفتن دادهها
|
||||
initialPageParam: undefined as string | undefined, // اولین درخواست بدون cursor
|
||||
getNextPageParam: (lastPage) => {
|
||||
const currentPage = lastPage.data?.pager?.page;
|
||||
const totalPages = lastPage.data?.pager?.totalPages;
|
||||
|
||||
if (!currentPage || !totalPages) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return currentPage < totalPages ? currentPage + 1 : undefined;
|
||||
return lastPage.nextCursor || undefined;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user