diff --git a/pages/search.tsx b/pages/search.tsx new file mode 100644 index 0000000..6031a33 --- /dev/null +++ b/pages/search.tsx @@ -0,0 +1,65 @@ +import { NextPage, NextPageContext } from 'next' +import dynamic from 'next/dynamic' +import { ParsedUrlQuery } from 'querystring' + +import { BotList } from '@types' +import { get } from '@utils/Query' +import { PageCount } from '@utils/Yup' +import NotFound from './404' + +const Hero = dynamic(() => import('@components/Hero')) +const Advertisement = dynamic(() => import('@components/Advertisement')) +const SEO = dynamic(() => import('@components/SEO')) +const BotCard = dynamic(() => import('@components/BotCard')) +const Container = dynamic(() => import('@components/Container')) +const Paginator = dynamic(() => import('@components/Paginator')) + +const Search:NextPage = ({ data, query }) => { + if(!data || data.data.length === 0) return + return <> + + + + +
+ { + data.data.map(bot => ) + } +
+ + +
+ +} + +export const getServerSideProps = async(ctx: Context) => { + let data: BotList + if(!ctx.query.page) ctx.query.page = '1' + const validate = await PageCount.validate(ctx.query.page).then(el => el).catch(() => null) + if(!validate || isNaN(Number(ctx.query.page))) data = null + else data = await get.list.search.load(JSON.stringify({ query: ctx.query.query, page: ctx.query.page })) + + return { + props: { + data, + query: ctx.query + } + } +} + + +interface SearchProps { + data: BotList, + query: URLQuery +} + +interface Context extends NextPageContext { + query: URLQuery +} + +interface URLQuery extends ParsedUrlQuery { + query: string + page?: string +} + +export default Search \ No newline at end of file