mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat: added pathname
This commit is contained in:
parent
0c3adbf9e5
commit
e201a76597
@ -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 <div className='flex flex-col items-center my-12 text-center justify-center'>
|
||||
<div className='flex text-gray-700 dark:text-gray-400'>
|
||||
<Link href={{ pathname: '/list/votes', query: { page: currentPage - 1} }}>
|
||||
<Link href={{ pathname, query: { page: currentPage - 1} }}>
|
||||
<a className={`${currentPage === 1 ? 'hidden' : ''} h-12 w-12 mr-1 flex justify-center items-center rounded-full transition duration-150 ease-in bg-gray-200 dark:bg-discord-black hover:bg-gray-300 dark:hover:bg-discord-dark-hover cursor-pointer text-center`}>
|
||||
<i className='fas fa-chevron-left'></i>
|
||||
</a>
|
||||
</Link>
|
||||
<div className='flex h-12 font-medium rounded-full bg-gray-200 dark:bg-discord-black'>
|
||||
<a className={`w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in rounded-l-full ${pages[0] === currentPage ? 'bg-gray-300 dark:bg-discord-dark-hover' : ' hover:bg-gray-300 dark:hover:bg-discord-dark-hover'}`}>{pages[0]}</a>
|
||||
<Link href={{ pathname, query: { page: pages[0] } }}>
|
||||
<a className={`w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in rounded-l-full ${pages[0] === currentPage ? 'bg-gray-300 dark:bg-discord-dark-hover' : ' hover:bg-gray-300 dark:hover:bg-discord-dark-hover'}`}>{pages[0]}</a>
|
||||
</Link>
|
||||
{
|
||||
pages[1] - pages[0] <= 1 ? pages[2] - pages[0] <= 1 ? '' : <a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in'>...</a> : <>
|
||||
<a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in'>...</a>
|
||||
<a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in hover:bg-gray-300 dark:hover:bg-discord-dark-hover'>{pages[1]}</a>
|
||||
pages[1] - pages[0] <= 1 ? pages[2] - pages[0] <= 1 ? '' : <a className='w-12 md:flex justify-center items-center leading-5 transition duration-150 ease-in'>...</a> : <>
|
||||
<a className='w-12 md:flex justify-center items-center leading-5 transition duration-150 ease-in'>...</a>
|
||||
<Link href={{ pathname, query: { page: pages[1] } }}>
|
||||
<a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in hover:bg-gray-300 dark:hover:bg-discord-dark-hover'>{pages[1]}</a>
|
||||
</Link>
|
||||
</>
|
||||
}
|
||||
<a className={`w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in ${currentPage === 1 || currentPage === totalPage ? 'hover:bg-gray-300 dark:hover:bg-discord-dark-hover' : 'bg-gray-300 dark:bg-discord-dark-hover '}`}>{pages[2] === pages[4] ? pages[4] - 1 : pages[2]}</a>
|
||||
<Link href={{ pathname, query: { page: pages[2] } }}>
|
||||
<a className={`w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in ${currentPage === 1 || currentPage === totalPage ? 'hover:bg-gray-300 dark:hover:bg-discord-dark-hover' : 'bg-gray-300 dark:bg-discord-dark-hover '}`}>{pages[2] === pages[4] ? pages[4] - 1 : pages[2]}</a>
|
||||
</Link>
|
||||
{
|
||||
pages[4] - pages[3] <= 1 ? pages[4] - pages[2] <= 1 ? '' : <a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in'>...</a> : <>
|
||||
<a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in hover:bg-gray-300 dark:hover:bg-discord-dark-hover'>{pages[3]}</a>
|
||||
<a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in'>...</a>
|
||||
pages[4] - pages[3] <= 1 ? pages[4] - pages[2] <= 1 ? '' : <a className='w-12 md:flex justify-center items-center leading-5 transition duration-150 ease-in'>...</a> : <>
|
||||
<Link href={{ pathname, query: { page: pages[3] } }}>
|
||||
<a className='w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in hover:bg-gray-300 dark:hover:bg-discord-dark-hover'>{pages[3]}</a>
|
||||
</Link>
|
||||
<a className='w-12 md:flex justify-center items-center leading-5 transition duration-150 ease-in'>...</a>
|
||||
</>
|
||||
}
|
||||
<a className={`w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in rounded-r-full ${pages[4] === currentPage ? 'bg-gray-300 dark:bg-discord-dark-hover' : ' hover:bg-gray-300 dark:hover:bg-discord-dark-hover'}`}>{pages[4]}</a>
|
||||
<Link href={{ pathname, query: { page: pages[4] } }}>
|
||||
<a className={`w-12 md:flex justify-center items-center cursor-pointer leading-5 transition duration-150 ease-in rounded-r-full ${pages[4] === currentPage ? 'bg-gray-300 dark:bg-discord-dark-hover' : ' hover:bg-gray-300 dark:hover:bg-discord-dark-hover'}`}>{pages[4]}</a>
|
||||
</Link>
|
||||
</div>
|
||||
<Link href={{ pathname: '/list/votes', query: { page: currentPage + 1} }}>
|
||||
<Link href={{ pathname, query: { page: currentPage + 1} }}>
|
||||
<a className={`${currentPage === totalPage ? 'hidden' : '' } h-12 w-12 ml-1 flex justify-center items-center rounded-full transition duration-150 ease-in bg-gray-200 dark:bg-discord-black hover:bg-gray-300 dark:hover:bg-discord-dark-hover cursor-pointer text-center`}>
|
||||
<i className='fas fa-chevron-right'></i>
|
||||
</a>
|
||||
@ -36,6 +46,7 @@ const Paginator = ({ currentPage, totalPage }:PaginatorProps):JSX.Element => {
|
||||
}
|
||||
|
||||
interface PaginatorProps {
|
||||
pathname: string
|
||||
currentPage: number
|
||||
totalPage: number
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ const Index: NextPage<IndexProps> = ({ votes, newBots, trusted }) => {
|
||||
votes.data.slice(0, 8).map(bot=> <BotCard key={bot.id} bot={bot} />)
|
||||
}
|
||||
</div>
|
||||
<Paginator totalPage={votes.totalPage} currentPage={votes.currentPage}/>
|
||||
<Paginator totalPage={votes.totalPage} currentPage={votes.currentPage} pathname='/list/votes' />
|
||||
<h1 className='text-3xl font-bold mt-20'>
|
||||
<i className='far fa-star mr-3 text-yellow-500' /> 새로운 봇
|
||||
</h1>
|
||||
|
||||
@ -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<VotesProps> = ({ data }:VotesProps) => {
|
||||
if(!data) return <NotFound />
|
||||
if(!data || data.data.length === 0) return <NotFound />
|
||||
return <Container paddingTop>
|
||||
<h1 className='text-3xl font-bold mt-5'>
|
||||
<i className='far fa-heart mr-3 text-pink-600' /> 하트 랭킹 - {data.currentPage}페이지
|
||||
@ -25,11 +26,12 @@ const Votes:NextPage<VotesProps> = ({ data }:VotesProps) => {
|
||||
data.data.map(bot => <BotCard key={bot.id} bot={bot} /> )
|
||||
}
|
||||
</div>
|
||||
<Paginator totalPage={data.totalPage} currentPage={data.currentPage} />
|
||||
<Paginator totalPage={data.totalPage} currentPage={data.currentPage} pathname='/list/votes' />
|
||||
</Container>
|
||||
}
|
||||
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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user