Fix: go back to previous page when last card on the last page is deleted (#17409)

This commit is contained in:
euvre
2026-07-28 19:30:28 +08:00
committed by GitHub
parent 679bce8f8d
commit 996c5156e5
6 changed files with 30 additions and 0 deletions

View File

@@ -110,6 +110,24 @@ export const useGetPaginationWithRouter = () => {
};
};
// When the current page becomes empty (e.g. after deleting the last card on
// the last page), navigate back to the previous page automatically.
export const useGoToPreviousPageOnEmpty = (
listLength: number | undefined,
loading: boolean = false,
) => {
const { pagination, setPagination } = useGetPaginationWithRouter();
useEffect(() => {
if (!loading && listLength === 0 && pagination.current > 1) {
setPagination({
page: pagination.current - 1,
pageSize: pagination.pageSize,
});
}
}, [listLength, loading, pagination, setPagination]);
};
export const useHandleSearchChange = () => {
const [searchString, setSearchString] = useState('');
const { pagination, setPagination } = useGetPaginationWithRouter();