diff --git a/components/Paginator.tsx b/components/Paginator.tsx index e57ccc6..888e6f1 100644 --- a/components/Paginator.tsx +++ b/components/Paginator.tsx @@ -1,31 +1,41 @@ import Link from 'next/link' -const Paginator = ({ currentPage, totalPage }:PaginatorProps):JSX.Element => { +const Paginator = ({ currentPage, totalPage, pathname }:PaginatorProps):JSX.Element => { const pages = [1, currentPage >= totalPage - 1 ? totalPage - 2 : currentPage - 1, currentPage <= 2 ? 2 : currentPage >= totalPage - 1 ? totalPage - 1 : currentPage, currentPage <= 2 ? 3 : currentPage + 1, totalPage ] return
- +
- {pages[0]} + + {pages[0]} + { - pages[1] - pages[0] <= 1 ? pages[2] - pages[0] <= 1 ? '' : ... : <> - ... - {pages[1]} + pages[1] - pages[0] <= 1 ? pages[2] - pages[0] <= 1 ? '' : ... : <> + ... + + {pages[1]} + } - {pages[2] === pages[4] ? pages[4] - 1 : pages[2]} + + {pages[2] === pages[4] ? pages[4] - 1 : pages[2]} + { - pages[4] - pages[3] <= 1 ? pages[4] - pages[2] <= 1 ? '' : ... : <> - {pages[3]} - ... + pages[4] - pages[3] <= 1 ? pages[4] - pages[2] <= 1 ? '' : ... : <> + + {pages[3]} + + ... } - {pages[4]} + + {pages[4]} +
- + @@ -36,6 +46,7 @@ const Paginator = ({ currentPage, totalPage }:PaginatorProps):JSX.Element => { } interface PaginatorProps { + pathname: string currentPage: number totalPage: number } diff --git a/pages/index.tsx b/pages/index.tsx index 7a571f4..6f86ab8 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -44,7 +44,7 @@ const Index: NextPage = ({ votes, newBots, trusted }) => { votes.data.slice(0, 8).map(bot=> ) }
- +

새로운 봇

diff --git a/pages/list/votes.tsx b/pages/list/votes.tsx index 337b136..1ece754 100644 --- a/pages/list/votes.tsx +++ b/pages/list/votes.tsx @@ -6,6 +6,7 @@ import { BotList } from '@types' import * as Query from '@utils/Query' import NotFound from '../404' +import { PageCount } from '@utils/Yup' const Advertisement = dynamic(()=> import('@components/Advertisement')) const BotCard = dynamic(()=> import('@components/BotCard')) @@ -13,7 +14,7 @@ const Container = dynamic(()=> import('@components/Container')) const Paginator = dynamic(()=> import('@components/Paginator')) const Votes:NextPage = ({ data }:VotesProps) => { - if(!data) return + if(!data || data.data.length === 0) return return

하트 랭킹 - {data.currentPage}페이지 @@ -25,11 +26,12 @@ const Votes:NextPage = ({ data }:VotesProps) => { data.data.map(bot => ) }

- + } export const getServerSideProps = async (ctx:Context) => { - if(isNaN(Number(ctx.query.page))) ctx.query.page = '1' + const validate = await PageCount.validate(ctx.query.page).then(el => el).catch(() => null) + if(isNaN(Number(ctx.query.page)) || !validate) ctx.query.page = '1' const data = await Query.get.list.votes.load(Number(ctx.query.page)) return { props: {