fix pagination

This commit is contained in:
smanylov
2026-05-06 19:12:37 +07:00
parent 8a72dbaf68
commit 84b07af246
2 changed files with 10 additions and 3 deletions
+3 -2
View File
@@ -22,7 +22,7 @@ export interface UseHistoryView {
export const useHistoryView = (page: number, size: number) => {
return useQuery({
queryKey: ['violationStatistic'],
queryKey: ['violationStatistic', page, size],
queryFn: () => {
return fetchHistoryView(page, size)
},
@@ -32,6 +32,7 @@ export const useHistoryView = (page: number, size: number) => {
}
return data;
},
retry: false
retry: false,
placeholderData: (previousData) => previousData // для оптимистичных обновлений
});
};
@@ -32,7 +32,7 @@ export function TrackingHistoryView() {
const tableData = apiResponse?.history || [];
const totalItems = apiResponse?.history.length || 0;
const totalPages = Math.ceil(totalItems / pagination.pageSize);
const totalPages = apiResponse?.totalPages || 0;
const viewport = useViewport();
@@ -244,6 +244,12 @@ export function TrackingHistoryView() {
getPaginationRowModel: getPaginationRowModel(),
});
useEffect(() => {
if (tableData.length === 0 && pagination.pageIndex > 0 && totalPages > 0) {
setPagination(prev => ({ ...prev, pageIndex: Math.max(0, totalPages - 1) }));
}
}, [tableData, pagination.pageIndex, totalPages]);
return (
<div
className="block-wrapper"