From 518d43bc6ee918738ebb5aa8413fbeea332aa9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Fri, 12 Feb 2021 13:07:53 +0900 Subject: [PATCH] fix: some bugs --- components/Paginator.tsx | 4 ++-- components/Search.tsx | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/components/Paginator.tsx b/components/Paginator.tsx index 48aa977..c829d9b 100644 --- a/components/Paginator.tsx +++ b/components/Paginator.tsx @@ -5,7 +5,7 @@ const Paginator = ({ currentPage, totalPage, pathname }:PaginatorProps):JSX.Elem else if(currentPage > totalPage - 3) pages = [ totalPage - 4 < 1 ? null : totalPage - 4, totalPage - 3 < 1 ? null : totalPage - 3, totalPage - 2 < 1 ? null : totalPage - 2, totalPage - 1 < 1 ? null : totalPage - 1, totalPage ] else pages = [ currentPage - 2 < 1 ? null : currentPage - 2, currentPage - 1 < 1 ? null : currentPage - 1, currentPage, currentPage + 1 > totalPage ? null : currentPage + 1, currentPage + 2 > totalPage ? null : currentPage + 2 ] pages = pages.filter(el => el) - return
+ return
@@ -14,7 +14,7 @@ const Paginator = ({ currentPage, totalPage, pathname }:PaginatorProps):JSX.Elem { pages.map((el, i) => - {el} + {el} ) } diff --git a/components/Search.tsx b/components/Search.tsx index 9f8fe24..1121034 100644 --- a/components/Search.tsx +++ b/components/Search.tsx @@ -1,14 +1,15 @@ import { useState } from 'react' +import { useRouter } from 'next/router' import Link from 'next/link' - -import { makeBotURL } from '@utils/Tools' +import { makeBotURL, redirectTo } from '@utils/Tools' import Fetch from '@utils/Fetch' import { BotList, ResponseProps } from '@types' import DiscordAvatar from '@components/DiscordAvatar' const Search = (): JSX.Element => { + const router = useRouter() const [ query, setQuery ] = useState('') const [ data, setData ] = useState>(null) const [ loading, setLoading ] = useState(false) @@ -25,12 +26,20 @@ const Search = (): JSX.Element => { setLoading(false) } - return <> + + const onSubmit = async () => { + setHidden(true) + redirectTo(router, `/search/?query=${encodeURIComponent(query)}`) + } + + return
setHidden(false)} onBlur={() => setTimeout(() => setHidden(true), 80)} className='relative w-full mt-5 text-black bg-white dark:text-gray-100 dark:bg-very-black flex rounded-lg z-10'> { SearchResults(e.target.value) + }} onKeyDown={(e) => { + if(e.key === 'Enter') return onSubmit() }} /> -
@@ -49,13 +58,13 @@ const Search = (): JSX.Element => {

- ) : loading ?
  • 검색중입니다...
  • :
  • {query && data ? data.errors && data.errors[0] || data.message?.includes('문법') ? <>검색 문법이 잘못되었습니다.
    더 알아보기 : data.message : query.length < 3 ? '최소 2글자 이상 입력해주세요.' : '검색어를 입력해주세요.'}
  • + ) : loading ?
  • 검색중입니다...
  • :
  • {query && data ? data.message?.includes('문법') ? <>검색 문법이 잘못되었습니다.
    더 알아보기 : data.errors && data.errors[0] || data.message : query.length < 3 ? '최소 2글자 이상 입력해주세요.' : '검색어를 입력해주세요.'}
  • }
    - +
    } export default Search