notifications

This commit is contained in:
hamid zarghami
2025-02-08 18:37:10 +03:30
parent f69b82efcc
commit 617041e2ba
8 changed files with 182 additions and 105 deletions
@@ -0,0 +1,17 @@
import * as api from "../service/NotificationService";
import { useInfiniteQuery } from "@tanstack/react-query";
export const useGetNotification = () => {
return useInfiniteQuery({
queryKey: ["notifications"],
queryFn: ({ pageParam = 1 }) => api.getNotifications(pageParam), // فراخوانی API برای گرفتن داده‌ها
initialPageParam: 1, // صفحه اول به طور پیشفرض
getNextPageParam: (lastPage) => {
const currentPage = lastPage.data?.pager.page;
const totalPages = lastPage.data?.pager.totalPages;
console.log("hasNextPage check: ", currentPage, totalPages); // بررسی وضعیت صفحات
return currentPage < totalPages ? currentPage + 1 : undefined;
},
});
};