mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 06:20:24 +00:00
feat: show search bar when scrolled
This commit is contained in:
parent
8c6043f013
commit
57ad6b5fa7
@ -11,6 +11,7 @@ import { useEffect, useState } from 'react'
|
|||||||
import { Nullable, User, UserCache } from '@types'
|
import { Nullable, User, UserCache } from '@types'
|
||||||
import Fetch from '@utils/Fetch'
|
import Fetch from '@utils/Fetch'
|
||||||
import { redirectTo } from '@utils/Tools'
|
import { redirectTo } from '@utils/Tools'
|
||||||
|
import Search from './Search'
|
||||||
|
|
||||||
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
||||||
|
|
||||||
@ -51,9 +52,20 @@ const Navbar: React.FC<NavbarProps> = ({ token }) => {
|
|||||||
setUserCache(null)
|
setUserCache(null)
|
||||||
}
|
}
|
||||||
}, [token])
|
}, [token])
|
||||||
|
const [scrolled, setScrolled] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleScroll = () => setScrolled(window.scrollY > 80)
|
||||||
|
window.addEventListener('scroll', handleScroll)
|
||||||
|
return () => window.removeEventListener('scroll', handleScroll)
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className='fixed top-0 left-0 right-0 z-50'>
|
||||||
<nav className='fixed top-0 z-40 flex w-full flex-wrap items-center justify-between bg-discord-blurple px-2 py-3 text-gray-100 dark:bg-discord-black lg:absolute'>
|
<nav className={`fixed top-0 z-40 flex w-full flex-wrap items-center justify-between px-2 py-2 text-gray-100 transition-colors duration-300 backdrop-blur-sm ${
|
||||||
|
scrolled || dev ? 'bg-discord-blurple dark:bg-discord-black' : 'bg-discord-blurple/30 dark:bg-discord-black/30'
|
||||||
|
} lg:absolute`}>
|
||||||
|
|
||||||
<div className='container mx-auto flex flex-wrap items-center justify-between px-4'>
|
<div className='container mx-auto flex flex-wrap items-center justify-between px-4'>
|
||||||
<div className='relative flex w-full justify-between lg:w-auto lg:justify-start'>
|
<div className='relative flex w-full justify-between lg:w-auto lg:justify-start'>
|
||||||
<Link
|
<Link
|
||||||
@ -168,7 +180,12 @@ const Navbar: React.FC<NavbarProps> = ({ token }) => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className='hidden grow items-center bg-white lg:flex lg:bg-transparent lg:shadow-none'>
|
{scrolled && (
|
||||||
|
<div className='hidden grow items-center justify-center px-6 lg:flex'>
|
||||||
|
<Search compact />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className='hidden lg:flex lg:items-center lg:bg-transparent lg:shadow-none'>
|
||||||
<ul className='flex list-none flex-col lg:ml-auto lg:flex-row'>
|
<ul className='flex list-none flex-col lg:ml-auto lg:flex-row'>
|
||||||
<li
|
<li
|
||||||
className='flex items-center outline-none'
|
className='flex items-center outline-none'
|
||||||
@ -376,7 +393,7 @@ const Navbar: React.FC<NavbarProps> = ({ token }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { Bot, ResponseProps, Server } from '@types'
|
||||||
import { useRouter } from 'next/router'
|
|
||||||
import Link from 'next/link'
|
|
||||||
import dynamic from 'next/dynamic'
|
|
||||||
import { makeBotURL, makeServerURL, redirectTo } from '@utils/Tools'
|
|
||||||
import Fetch from '@utils/Fetch'
|
import Fetch from '@utils/Fetch'
|
||||||
import { Bot, Server, ResponseProps } from '@types'
|
import { makeBotURL, makeServerURL, redirectTo } from '@utils/Tools'
|
||||||
|
import dynamic from 'next/dynamic'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
import Day from '@utils/Day'
|
import Day from '@utils/Day'
|
||||||
import useOutsideClick from '@utils/useOutsideClick'
|
import useOutsideClick from '@utils/useOutsideClick'
|
||||||
@ -12,7 +12,11 @@ import useOutsideClick from '@utils/useOutsideClick'
|
|||||||
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
||||||
const ServerIcon = dynamic(() => import('@components/ServerIcon'))
|
const ServerIcon = dynamic(() => import('@components/ServerIcon'))
|
||||||
|
|
||||||
const Search: React.FC = () => {
|
interface SearchProps {
|
||||||
|
compact?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const Search: React.FC<SearchProps> = ({ compact = false }) => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const ref = useRef()
|
const ref = useRef()
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
@ -101,12 +105,13 @@ const Search: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onFocus={() => setHidden(false)} ref={ref}>
|
<div className={`relative w-full z-10 ${compact ? '' : 'mt-5'}`}>
|
||||||
<div className='relative z-10 mt-5 flex w-full rounded-lg bg-white text-black dark:bg-very-black dark:text-gray-100'>
|
<div onFocus={() => setHidden(false)} ref={ref}>
|
||||||
|
<div className={`relative z-10 flex w-full items-center bg-white text-black dark:bg-very-black dark:text-gray-100 ${compact ? 'h-10 px-3 rounded-md' : 'rounded-lg'}`}>
|
||||||
<input
|
<input
|
||||||
type='search'
|
type='search'
|
||||||
maxLength={50}
|
maxLength={50}
|
||||||
className='h-16 grow border-0 border-none bg-transparent px-7 py-3 pr-20 text-xl shadow outline-none'
|
className={`grow border-0 border-none bg-transparent pr-20 shadow outline-none ${compact ? 'h-10 text-sm' : 'h-16 px-7 py-3 text-xl'}`}
|
||||||
placeholder='검색...'
|
placeholder='검색...'
|
||||||
value={query}
|
value={query}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
@ -119,14 +124,14 @@ const Search: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
className='cusor-pointer absolute right-0 top-0 mr-5 mt-5 outline-none'
|
className='absolute right-4 top-1/2 -translate-y-1/2 outline-none'
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
>
|
>
|
||||||
<i className='fas fa-search text-2xl text-gray-600 hover:text-gray-700' />
|
<i className={`fas fa-search text-gray-600 hover:text-gray-700 ${compact ? 'text-sm' : 'text-2xl'}`} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className={`relative ${hidden ? 'hidden' : 'block'} z-50`}>
|
<div className={`relative ${hidden ? 'hidden' : 'block'} z-50`}>
|
||||||
<div className='pin-t pin-l absolute my-2 h-60 w-full overflow-y-scroll rounded bg-white text-black shadow-md dark:bg-very-black dark:text-gray-100 md:h-80'>
|
<div className='absolute top-full mt-2 max-h-60 w-full overflow-y-auto rounded bg-white text-black shadow-md dark:bg-very-black dark:text-gray-100 md:h-80'>
|
||||||
<ul>
|
<ul>
|
||||||
{data && data.code === 200 ? (
|
{data && data.code === 200 ? (
|
||||||
<div className='grid lg:grid-cols-2'>
|
<div className='grid lg:grid-cols-2'>
|
||||||
@ -172,7 +177,7 @@ const Search: React.FC = () => {
|
|||||||
<li className='px-3 py-3.5'>검색중입니다...</li>
|
<li className='px-3 py-3.5'>검색중입니다...</li>
|
||||||
</ul>
|
</ul>
|
||||||
) : (
|
) : (
|
||||||
<ul>
|
<ul className='px-3 py-3.5'>
|
||||||
{query && data ? (
|
{query && data ? (
|
||||||
data.message?.includes('문법') ? (
|
data.message?.includes('문법') ? (
|
||||||
<li className='px-3 py-3.5'>
|
<li className='px-3 py-3.5'>
|
||||||
@ -194,10 +199,10 @@ const Search: React.FC = () => {
|
|||||||
)
|
)
|
||||||
) : query.length === 0 ? (
|
) : query.length === 0 ? (
|
||||||
!recentSearch || !Array.isArray(recentSearch) || recentSearch.length === 0 ? (
|
!recentSearch || !Array.isArray(recentSearch) || recentSearch.length === 0 ? (
|
||||||
<li className='px-3 py-3.5'>최근 검색 기록이 없습니다.</li>
|
<li >최근 검색 기록이 없습니다.</li>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<li className='h-15 cursor-pointer px-3 py-2 font-semibold'>
|
<li className='h-15 cursor-pointer font-semibold'>
|
||||||
최근 검색어
|
최근 검색어
|
||||||
<button
|
<button
|
||||||
className='absolute right-0 pr-10 text-sm text-red-500 hover:opacity-90'
|
className='absolute right-0 pr-10 text-sm text-red-500 hover:opacity-90'
|
||||||
@ -236,6 +241,7 @@ const Search: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user