fix pagination
This commit is contained in:
@@ -22,7 +22,7 @@ export interface UseHistoryView {
|
|||||||
|
|
||||||
export const useHistoryView = (page: number, size: number) => {
|
export const useHistoryView = (page: number, size: number) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['violationStatistic'],
|
queryKey: ['violationStatistic', page, size],
|
||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
return fetchHistoryView(page, size)
|
return fetchHistoryView(page, size)
|
||||||
},
|
},
|
||||||
@@ -32,6 +32,7 @@ export const useHistoryView = (page: number, size: number) => {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
retry: false
|
retry: false,
|
||||||
|
placeholderData: (previousData) => previousData // для оптимистичных обновлений
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -32,7 +32,7 @@ export function TrackingHistoryView() {
|
|||||||
|
|
||||||
const tableData = apiResponse?.history || [];
|
const tableData = apiResponse?.history || [];
|
||||||
const totalItems = apiResponse?.history.length || 0;
|
const totalItems = apiResponse?.history.length || 0;
|
||||||
const totalPages = Math.ceil(totalItems / pagination.pageSize);
|
const totalPages = apiResponse?.totalPages || 0;
|
||||||
|
|
||||||
const viewport = useViewport();
|
const viewport = useViewport();
|
||||||
|
|
||||||
@@ -244,6 +244,12 @@ export function TrackingHistoryView() {
|
|||||||
getPaginationRowModel: getPaginationRowModel(),
|
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
className="block-wrapper"
|
className="block-wrapper"
|
||||||
|
|||||||
Reference in New Issue
Block a user