From 448343335d4b9dac7c2079244d1f9233837a6e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Mon, 25 Jan 2021 21:33:32 +0900 Subject: [PATCH] fix: fixed paginator --- components/Paginator.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/components/Paginator.tsx b/components/Paginator.tsx index a52ed2c..73fb3aa 100644 --- a/components/Paginator.tsx +++ b/components/Paginator.tsx @@ -1,7 +1,6 @@ import Link from 'next/link' - const Paginator = ({ currentPage, totalPage }:PaginatorProps):JSX.Element => { - const pages = [currentPage === 1 ? 2 : currentPage === 2 ? 1 : currentPage - 2, currentPage === 1 || currentPage === 2 ? 3 : currentPage - 1, currentPage, currentPage === 1 || currentPage === 2 ? 4 : currentPage + 1, currentPage === 1 || currentPage === 2 ? 5 : currentPage + 2] + const pages = [1, currentPage - 1, currentPage, currentPage + 1, totalPage ] return
@@ -10,12 +9,21 @@ const Paginator = ({ currentPage, totalPage }:PaginatorProps):JSX.Element => {
- - - - = totalPage ? 'hidden ' : `md:flex ${(pages[4]) >= totalPage ? 'rounded-r-full' : ''}`}w-12 justify-center items-center hidden cursor-pointer leading-5 transition duration-150 ease-in hover:bg-gray-400 dark:hover:bg-discord-dark-hover order-8`}>{pages[3]} - = totalPage ? 'hidden ' : 'md:flex rounded-r-full'}w-12 justify-center items-center hidden cursor-pointer leading-5 transition duration-150 ease-in hover:bg-gray-400 dark:hover:bg-discord-dark-hover order-9`}>{pages[4]} - {pages[2]} + {pages[0]} + { + pages[1] - pages[0] <= 1 ? '' : <> + ... + {pages[1]} + + } + {pages[2] === pages[4] ? pages[4] - 1 : pages[2]} + { + pages[4] - pages[3] <= 1 ? '' : <> + {pages[3]} + ... + + } + {pages[4]}