From a99c30ff11f92965194ca3612f237440984f7d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Sat, 23 Jan 2021 11:47:22 +0900 Subject: [PATCH] feat: added paginator --- components/Paginator.tsx | 35 ++++++++++++++++++++++++++++ pages/index.tsx | 15 ++++++++---- pages/list/votes.tsx | 50 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 components/Paginator.tsx create mode 100644 pages/list/votes.tsx diff --git a/components/Paginator.tsx b/components/Paginator.tsx new file mode 100644 index 0000000..a52ed2c --- /dev/null +++ b/components/Paginator.tsx @@ -0,0 +1,35 @@ +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] + return
+
+ + + + + +
+ + + + = 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]} +
+ + + + + +
+
+ +} + +interface PaginatorProps { + currentPage: number + totalPage: number +} + +export default Paginator \ No newline at end of file diff --git a/pages/index.tsx b/pages/index.tsx index 87eb866..49201fe 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,8 +1,12 @@ -import { NextPage, } from 'next' +import { NextPage } from 'next' import dynamic from 'next/dynamic' +import Paginator from '../components/Paginator' +import Search from '../components/Search' +import Tag from '../components/Tag' import { BotList } from '../types' import { Query } from '../utils' +import { cats } from '../utils/Constants' const Advertisement = dynamic(()=> import('../components/Advertisement')) const Container = dynamic(()=> import('../components/Container')) @@ -17,6 +21,11 @@ const Index: NextPage = ({ votes, newBots, trusted }) => {

한국 디스코드봇 리스트

+ +

카테고리로 찾아보기

+
+ { cats.map(t=> ) } +
= ({ votes, newBots, trusted }) => { votes.data.slice(0, 8).map(bot=> ) } - - 더보기 - +

새로운 봇

diff --git a/pages/list/votes.tsx b/pages/list/votes.tsx new file mode 100644 index 0000000..5e12437 --- /dev/null +++ b/pages/list/votes.tsx @@ -0,0 +1,50 @@ +import { NextPage, NextPageContext } from 'next' +import { ParsedUrlQuery } from 'querystring' +import Advertisement from '../../components/Advertisement' +import BotCard from '../../components/BotCard' + +import Container from '../../components/Container' +import Paginator from '../../components/Paginator' +import { BotList } from '../../types' +import { Query } from '../../utils' +import NotFound from '../404' + +const Votes:NextPage = ({ data }:VotesProps) => { + if(!data) return + return +

+ 하트 랭킹 - {data.currentPage}페이지 +

+

하트를 많이 받은 봇들의 순위입니다!

+ +
+ { + data.data.map(bot => ) + } +
+ +
+} +export const getServerSideProps = async (ctx:Context) => { + if(isNaN(Number(ctx.query.page))) ctx.query.page = '1' + const data = await Query.get.list.votes.load(Number(ctx.query.page)) + return { + props: { + data + } + } +} + +interface VotesProps { + data: BotList +} + +interface Context extends NextPageContext { + query: URLQuery +} + +interface URLQuery extends ParsedUrlQuery { + page: string +} + +export default Votes