/
GEOSHEV
/
Admin-Panel.Course-project
Обзор
Документация
Войти
/
GEOSHEV
/
Admin-Panel.Course-project
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/lib/utils.ts
32 строки
984 B
Gosha
add userPagination
01 май 2025, 19:34
01 май 2025, 19:34
29f77c5
Код
Авторство
О чём код?
export const generatePagination = (currentPage: number, totalPages: number) => { // If the total number of pages is 7 or less, // display all pages without any ellipsis. if (totalPages <= 7) { return Array.from({ length: totalPages }, (_, i) => i + 1); } // If the current page is among the first 3 pages, // show the first 3, an ellipsis, and the last 2 pages. if (currentPage <= 3) { return [1, 2, 3, "...", totalPages - 1, totalPages]; } // If the current page is among the last 3 pages, // show the first 2, an ellipsis, and the last 3 pages. if (currentPage >= totalPages - 2) { return [1, 2, "...", totalPages - 2, totalPages - 1, totalPages]; } // If the current page is somewhere in the middle, // show the first page, an ellipsis, the current page and its neighbors, // another ellipsis, and the last page. return [ 1, "...", currentPage - 1, currentPage, currentPage + 1, "...", totalPages, ]; };